4

I am really stumped on this one, I have a page that I am using to collect data on what methods are being called in my web application. When I run my application from visual studio, there is no problem, everything works great, all my server and client methods function as expected.

However, when I deploy this application to my webserver running IIS 7.5 on windows server 2008, R2 SP1 my client side methods do not consistently fire, everything looks like its running fine. but the triggering client event never happens.

Client Side Javascript:

var nlog = $.connection.centralHub;
$.connection.hub.logging = true;

$(function () {
    var logTable = $("#logTable");

    nlog.client.logevent = function (datetime, siteName, clientConId, logLevel, message, stack, eMessage) {
    var tr = $("<tr>");
        tr.append($("<td>").text(datetime));
        tr.append($("<td>").text(siteName));
        tr.append($("<td>").text(clientConId));
        tr.append($("<td>").text(logLevel));
        tr.append($("<td style='white-space: pre;'>").text(message));
        tr.append($("<td>").text(stack));
        tr.append($("<td>").text(eMessage));
        logTable.append(tr);
    };
    nlog.client.test = function() {
        $("#test").text("spit out a test");
    }
    $.connection.hub.start().done(function () {
        nlog.server.initialMessage();
        nlog.server.test();
    }, 5000);
});

Server Hub methods:

Hub Method: CentralHub

public void InitialMessage()
    {
        string connId = Context.ConnectionId;
        _clientTracker.InitalMessage(connId);
    } 

internal void InitalMessage(string connId)
    {

        Clients.All.logEvent(
            DateTime.Now.ToString("F"),
            "Harper Woods",
            connId,
            "info",
            "Hub Started",
            "No Message",
            "No Message");
    }

Google Console output from my IIS webserver

  • [12:14:22 GMT-0400 (Eastern Daylight Time)] SignalR: Client subscribed to hub 'centralhub'

  • [12:14:22 GMT-0400 (Eastern Daylight Time)] SignalR: Negotiating with '/signalr/negotiate?connectionData=%5B%7B%22name%22%3A%22centralhub%22%7D%5D&clientProtocol=1.3'. jquery.signalR-2.0.3.js:76

  • [12:14:22 GMT-0400 (Eastern Daylight Time)] SignalR: Attempting to connect to SSE endpoint 'http://tcdev.citadelsystems.com/signalr/connect?transport=serverSentEvents&…7Hb0f69Gs1q&connectionData=%5B%7B%22name%22%3A%22centralhub%22%7D%5D&tid=2'. jquery.signalR-2.0.3.js:76
  • [12:14:22 GMT-0400 (Eastern Daylight Time)] SignalR: EventSource connected. jquery.signalR-2.0.3.js:76
  • [12:14:22 GMT-0400 (Eastern Daylight Time)] SignalR: Now monitoring keep alive with a warning timeout of 13333.333333333332 and a connection lost timeout of 20000. jquery.signalR-2.0.3.js:76
  • [12:14:22 GMT-0400 (Eastern Daylight Time)] SignalR: Invoking centralhub.InitialMessage jquery.signalR-2.0.3.js:76
  • [12:14:22 GMT-0400 (Eastern Daylight Time)] SignalR: Invoking centralhub.Test jquery.signalR-2.0.3.js:76
  • [12:14:22 GMT-0400 (Eastern Daylight Time)] SignalR: Invoked centralhub.InitialMessage jquery.signalR-2.0.3.js:76
  • [12:14:22 GMT-0400 (Eastern Daylight Time)] SignalR: Invoked centralhub.Test

Google Console Output from Visual Studio 2013

  • [12:17:56 GMT-0400 (Eastern Daylight Time)] SignalR: Client subscribed to hub 'centralhub'.jquery.signalR-2.0.3.js:76

  • [12:17:56 GMT-0400 (Eastern Daylight Time)] SignalR: Negotiating with '/signalr/negotiate?connectionData=%5B%7B%22name%22%3A%22centralhub%22%7D%5D&clientProtocol=1.3'. jquery.signalR-2.0.3.js:76

  • [12:17:57 GMT-0400 (Eastern Daylight Time)] SignalR: Attempting to connect to SSE endpoint 'http://localhost:32568/signalr/connect?transport=serverSentEvents&connectio…kMTNQps1lto&connectionData=%5B%7B%22name%22%3A%22centralhub%22%7D%5D&tid=3'. jquery.signalR-2.0.3.js:76

  • [12:17:57 GMT-0400 (Eastern Daylight Time)] SignalR: EventSource connected. jquery.signalR-2.0.3.js:76

  • [12:17:57 GMT-0400 (Eastern Daylight Time)] SignalR: Now monitoring keep alive with a warning timeout of 13333.333333333332 and a connection lost timeout of 20000. jquery.signalR-2.0.3.js:76

  • [12:17:57 GMT-0400 (Eastern Daylight Time)] SignalR: Invoking centralhub.InitialMessage jquery.signalR-2.0.3.js:76

  • [12:17:57 GMT-0400 (Eastern Daylight Time)] SignalR: Invoking centralhub.Test jquery.signalR-2.0.3.js:76

  • [12:17:57 GMT-0400 (Eastern Daylight Time)] SignalR: Triggering client hub event 'logEvent' on hub 'CentralHub'. jquery.signalR-2.0.3.js:76

  • [12:17:57 GMT-0400 (Eastern Daylight Time)] SignalR: Triggering client hub event 'test' on hub 'CentralHub'. jquery.signalR-2.0.3.js:76

  • [12:17:57 GMT-0400 (Eastern Daylight Time)] SignalR: Invoked centralhub.Test jquery.signalR-2.0.3.js:76

  • [12:17:57 GMT-0400 (Eastern Daylight Time)] SignalR: Invoked centralhub.InitialMessage

matt.
  • 2,355
  • 5
  • 32
  • 43
Kelso Sharp
  • 972
  • 8
  • 12

3 Answers3

0

Ok, I finally was able to find a bit of information on what is going on here. It is where you set the dependency injection resolver for signalr, this MUST be done in the Application_Start() method of the Global.asax, you cannot rely on ninject web bootstrapper, and you cannot put it in the owin startup class like the example on ASP.NET site. It will not function predictably it will work sometimes, but you will miss messages.

Kelso Sharp
  • 972
  • 8
  • 12
  • Did putting dependency injection resolver in `Application_Start()` solve your problem? I have the same issue and I tried that but still hub events are sometimes not triggered. – Sobhan Apr 24 '16 at 06:32
0

I had this same exact issue. My SignalR Application would work perfectly in Visual Studio or Windows Local OS IIS. But when I deployed it to IIS 7.5 on Windows Server 2008 R2, the client methods wouldn't get invoked consistently. That was all because my application pool in deployment IIS server, had 10 working processors (i.e. Web Garden). This post helped me realize this and when I set the working processors to 1, It did the trick. Apparently this is by design.

From @AlexanderKöplinger:

This is by design. The two worker processes don't share state and clients will be distributed between them on a round-robin basis, which means 50% will connect to process A and 50% to process B. As the underlying SignalR message bus is in-memory by default, process A doesn't see messages from process B.

I'll set the working processor to 1 for now, but I'll try to find a way to make Web Garden work with SignalR.

Update:

Setting working processors to 1 is not good in regards of scaling. The SignalR team did provide us a way to make Web Garden work with SignalR and it's explained here. You have 3 methods to choose from and I decided to use the SQL server approach. The setup went smooth and easy and now SignalR is using SQL server as a backplane to share messages between different working processors.

Community
  • 1
  • 1
Sobhan
  • 1,051
  • 2
  • 13
  • 29
  • 1
    I think that Alexander is correct, I have not looked at this issue for a long time, and I no longer have access to the codebase or the hardware to double check. What does not make sense to me however is you set your CPU's to 1 then your threads are going to get blocked. Signalr was built to handle multi-threading, Where is this falling down in regards to signalr itself. It was built specifically to handle messaging from multiple clients. It does not make sense to me that there is no way to resolve this issue within code. – Kelso Sharp May 09 '16 at 16:59
  • @KelsoSharp, You are correct. Setting working processors to 1 is not good in regards of scaling. The SignalR team did provide us a way to make Web Garden work with SignalR and [it's explained here.](http://www.asp.net/signalr/overview/performance/scaleout-in-signalr). You have 3 methods to choose from and I decided to use the [SQL server approach](http://www.asp.net/signalr/overview/performance/scaleout-with-sql-server). – Sobhan May 09 '16 at 21:41
0

At first sight, within your done() you are calling a Test method from the server which doesn’t exist or at least is missing. Removing this line could make it work.

dotnetspark
  • 551
  • 4
  • 23