SignalR gets stuck on the 'Initiating start request' screen, halting all progress

SignalR has been causing some strange behavior for me lately. After doing some refactoring, I started experiencing connectivity issues. It seems like my code was just lucky to work before because it didn't follow the recommended practices. For example, I was starting the hub before declaring the hub methods, as pointed out by David Fowler, so the client wasn't explicitly subscribing to those hubs, yet somehow it still worked. I've spent all day trying to figure out why and how this happened.

After refactoring, here is the code that runs once the document is loaded:

function initSignalR() {
   var me = this,
    appointmentHub = $.connection.appointmentHub,
    assignmentHub = $.connection.assignmentHub,
    taskHub = $.connection.taskHub,      
    notificationHub = $.connection.notificationHub,
    messageHub = $.connection.messageHub;

  $.connection.hub.connectionSlow(onConnectionSlow);
  $.connection.hub.stateChanged(onStateChanged);
  $.connection.hub.error(onError);
  $.connection.hub.disconnected(onDisconnected);
  $.connection.hub.logging = true;

  appointmentHub.client.updateAppointment = onUpdateAppointment;    
  $.connection.hub.start().done(onDone).fail(onFailed);
   ... code omitted for brevity ...
}

function onUpdatedAppointment(appointment) {
 .... code omitted for brevity ....
}

These logs occasionally appear in the console when it works:

Client subscribed to hub 'appointmenthub'
 Negotiating with '/signalr/negotiate?clientProtocol=1.5&connectionData=%5B%7B%22name%22%3A%22appointmenthub%22%7D%5D'
webSockets transport starting.
Connecting to websocket endpoint 'ws://localhost:52541/signalr/connect?....
Websocket opened.
webSockets transport connected. Initiating start request.
The start request succeeded. Transitioning to the connected state.
Now monitoring keep alive with a warning timeout of 13333.333333333332, keep alive timeout of 20000 and disconnecting timeout of 30000

I intentionally used the word 'occasionally' because SignalR only connects correctly every now and then. Most of the time, the last visible step in the console is:

webSockets transport connected. Initiating start request.

I thought the callback method body might be the issue at first. I noticed I could connect more often with an empty function, but even that didn't solve the problem. I'm running out of ideas on what to do next.

For completeness, here is the startup code in ASP.NET MVC:

GlobalHost.Configuration.TransportConnectTimeout = TimeSpan.FromSeconds(50);
GlobalHost.Configuration.ConnectionTimeout = TimeSpan.FromSeconds(110);

GlobalHost.HubPipeline.AddModule(new ErrorHandlingPipelineModule());    
GlobalHost.DependencyResolver.Register(typeof(IJavaScriptMinifier), () => new SignalRMinifier());
GlobalHost.DependencyResolver.Register(typeof(IUserIdProvider), () => new UserIdProvider());

HubConfiguration hubConfiguration = new HubConfiguration()
{                 
   EnableDetailedErrors = true,  
};

return app.MapSignalR(hubConfiguration);

I came across a similar issue but no solution was provided there.

I have tested this in IE/Edge/Chrome/Firefox/Opera, and they all show the same results. The application is using ASP.NET MVC5 and the latest version of SignalR (2.2.1).

Answer №1

After investigating the situation, it was determined that the issue did not lie within the client-side code or SignalR configuration. The problem actually resided in the Hub class.

Specifically, there was custom code in the OnConnected method causing timeouts and errors due to connections with external services and databases. By offloading this work to a separate process (such as Hangfire or NServiceBus), the issue was successfully resolved, as previously mentioned.

In retrospect, the behavior observed aligns logically. This experience highlighted the importance of treating Hubs akin to controllers in ASP.NET MVC: keeping them lightweight and avoiding excessive business logic.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Display a modal popup when a radio button is clicked

<tr> <td align="left">Have you requested the employee to leave without serving the notice period</td> <td align="left"> <asp:RadioButton ID="rdoBtnleaveWoNoticeyes" runat="server" GroupName="Replacement" ...

div or paragraph element nested within a flex container

How can I make the logo text div tag, called Title, take up its content space inside the parent flexbox without wrapping? I prefer not to set the Title div to 100% or use white-space: nowrap. I simply want it to behave like a regular div where it fills it ...

When combining React and ReactDOM with browserify, the resulting bundle size exceeds that of react.min.js and react-dom.min.js

I'm currently working through the React beginner's tutorial and things are going smoothly so far. However, I decided to delve into importing external packages and began using tools like npm, browserify, watchify, etc. In the tutorial, there is a ...

Discover the element's selector for the event that was triggered using jQuery

In the process of creating a lightweight real-time application, we are utilizing jQuery's event system to facilitate communication between modules. Any changes made in the DOM that affect elements outside the module are achieved through triggering eve ...

Loading jQuery on an ajax request

The loader is working with the code now, but it is not replacing and calling the URL. The ajax url call should be placed within searchable. <button onclick="myFunction()">LOAD</button><br /><br /> <div class="spinner bar hide" ...

Tips for utilizing JSON.parse

Within my ajax request, I am encountering the following code: 403: function(jqXHR) { var error = jqXHR.responseText; console.log(error); } When this error occurs, a message is displayed in the console: Htt ...

Combining intersecting sets within an array of sets

I am working with an array that contains minimum and maximum values for various sets. Here is an example of what the array looks like: Array ( [0] => Array ( [0] => 1200 [1] => 2400 ) [1] => Arr ...

Shared codes are compatible with both C and Javascript programming languages

Within the scope of this project, data will be retrieved from the server in either JSON or XML format. There are two separate client applications that will handle the data processing, with one being web-based and written in JavaScript, while the other is ...

What is the process for incorporating a glossiness / specular texture onto a GLTF model?

QUERY: I currently possess a specular/glossiness texture image for a model that has not yet been integrated into the GLTF model. Is there a way to incorporate/add this texture to my model in order to achieve a reflective/glossy appearance where required? ...

jQuery UI Slider is malfunctioning (code example included)

I've implemented a jQuery UI slider on my website, and it's functioning quite well. You can check out the slider HERE. However, I've noticed that when I click on 'back to the top', the page smoothly scrolls up. But when I use the ...

Combine strings in PHP with an alert box in JavaScript

Is there a way to concatenate a string in a JavaScript alert box? I want the first part of the alert box to be a simple text, while the second part is a string retrieved from a MySQL table. $myname = $row["name"]; echo ' <scri ...

Choose the CSS class based on the content provided

Help needed with CSS issue. I want to target the <tr> element's class using Bootstrap classes like .success or .danger. In my Vue.js project, the status name in my object does not align with the .success or .danger classes, but I still need to ...

The "initialized" event in angular2-tree-component fires prior to the data being loaded

Utilizing the angular2-tree-component, my goal is to display an already expanded tree. According to Angular docs, the initialized event should be used for expanding the tree after the data has been received: This event triggers after the tree model has ...

trouble with maintaining nodejs mariadb connection

Hello, I am working with nodejs to create a rest API However, I have encountered an issue Let's take a look at the code var http = require('http'); var url = require('url'); var mariadb = require('mariadb'); http.c ...

ReactJS encountered an error: _this3.onDismissID is not defined as a function

My goal is to retrieve the latest news related to a specific search term from a website, showcase them, and provide a dismiss button next to each news item for users to easily remove them if desired. Here's a snippet of the code I'm using: import ...

Tips for organizing data and dynamically linking options to another select value?

One of my challenges involves working with two select elements. The first select allows for multiple options, while the second select is dependent on the choice made in the first one. <select class="form-control" id="select1"> <option value=""& ...

Creating intricate mazes using canvas drawing techniques

I recently developed a maze generator as a personal project utilizing a graph. While the generation logic works perfectly, I am facing challenges when it comes to rendering the maze. In my approach, each cell is represented by an array of 4 edges where the ...

Entwine words around an immovable partition

Is it possible to create an HTML element that remains fixed in place even as the content on the webpage changes, with everything else adjusting around it? I am looking to add a continuous line that spans across a dynamic webpage. No matter how much conten ...

Activate Input by Clicking on Label in Internet Explorer version 8

I am trying to implement a widget in JQuery colorbox that allows users to load files. My approach involves using an input tag with type='file' and styling it with visibility:hidden. Additionally, I have created two labels that are styled like but ...

"Exploring the world of jest.doMock: A guide to mocking

Here is the code snippet I am testing: ... import data from '../data/mock.json'; // function is async export const something = async () => { try { ... if (!data) { throw 'error is here!'; } ...