locked
Group broadcast stops working after certain period RRS feed

  • Question

  • User-1950972991 posted

    I have pretty straightforward setup of SignalR:

    • An ASP.NET WebAPI site under IIS, which runs SignalR hub - server part of my application
    • A windows service, which is to be seen as SignalR client

    So client connects to server hub and joins to a group. From time to time server calls one client method via group broadcast.
    There are many clients connected, but each one is joined to a single-entry group.

    This runs smoothly for a while - seems to be some hours, but I'm not really sure, if it depends on activity in channel or not. But then calls do not reach client anymore, until client closes connection and starts it new. You can find very similar behavior, described in this thread: https://forums.asp.net/t/2124874.aspx?Calling+a+method+from+the+hub+to+a+Group+of+Clients+Stops+Working+after+a+while+

    But my setup is simpler - there is no persistent storage on server side. Just really plain SignalR out of the box.

    What is especially interesting, I thought, that maybe connection is somehow silently lost. But this doesn't seem to be a case. I've implemented a manual "heart beat" functionality: there is method on client side "ListenToHeartBeat" which is called by server every 15 seconds. These calls always work! Even when group broadcast do not reach client anymore, the heart beat passes through fine. More over, calling server-side method is also working fine. So just like jaked16 in the link above, I also suspect, that group membership is lost for some reason.

    In IIS the application pool is configured with Idle Timeout = 0. So pool is always running. There is also only one single instance, processing requests.

    Finally, group and heart beat broadcasts are called like this:

    • Group: hubContext.Clients.Group("someGroupName").ExportData(val);
    • Heart beat: hubContext.Clients.All.HeartBeat();

    Does anyone has some ideas, what could be the reason for group calls stopping to work after a while?

    Thursday, November 23, 2017 10:01 AM

All replies

  • User-335504541 posted

    Hi Sergej Semeniaka,

    So just like jaked16 in the link above, I also suspect, that group membership is lost for some reason.

    According to your description, I think it could be your user's authentication status may change. For example your site uses sliding expiration with Forms Authentication, and there is no activity to keep the authentication cookie valid.

    You can fix this problem by adding some script that periodically requests a resource on the web server to keep the authentication cookie valid.

    For example:

    $(function () {
        setInterval(function() {
            $.ajax({
                url: "Ping.aspx",
                cache: false
            });
        }, 1800000);
    });

    Here is the reference:

    https://docs.microsoft.com/en-us/aspnet/signalr/overview/security/introduction-to-security#signalr-security-recommendations

    And you could refer to the link below for more information:

    https://stackoverflow.com/questions/28683940/signalr-stops-working-after-a-while

    Best Regards,

    Billy

    Friday, November 24, 2017 7:39 AM
  • User-1950972991 posted

    Hello Billy Liu,

    Thank you for answer!

    I'm not using any authentication for hub. ASP.NET WebApi on its turn uses JWT token authorization. But this doesn't affect SignalR part.

    Also if the authentication would be the reason, I guess, that also broadcasting to all clients would stop working. But this is not the case - only group broadcast
    doesn't work.

    Friday, November 24, 2017 7:49 AM
  • User-335504541 posted

    Hi Sergej Semeniaka,

    I'm not using any authentication for hub.

    I was talk about the user's authentication not the server.

    And how many clients in your group? A group will be deleted when the last connection from membership is removed.

    Best Regards,

    Billy

    Friday, November 24, 2017 8:56 AM
  • User-1950972991 posted

    Hello Billy Liu,

    There is no authentication on any side.

    As I wrote above, each group has only one client. There are no disconnects logged on client side, so group should be present..

    Sergej.

    Friday, November 24, 2017 8:58 AM
  • User-335504541 posted

    Hi Sergej Semeniaka,

    There are no disconnects logged on <g class="gr_ gr_18 gr-alert gr_gramm gr_inline_cards gr_disable_anim_appear Grammar only-ins replaceWithoutSep" id="18" data-gr-id="18">client</g> side, so <g class="gr_ gr_19 gr-alert gr_gramm gr_inline_cards gr_disable_anim_appear Grammar only-ins replaceWithoutSep" id="19" data-gr-id="19">group</g> should be <g class="gr_ gr_20 gr-alert gr_gramm gr_inline_cards gr_disable_anim_appear Punctuation multiReplace" id="20" data-gr-id="20">present..</g>

    How did you log the disconnects?

    I think you could try to handle the <g class="gr_ gr_14 gr-alert gr_spell gr_inline_cards gr_disable_anim_appear ContextualSpelling ins-del multiReplace" id="14" data-gr-id="14">connectionSlow</g> event to log a message if there are connection problems.

    You could refer the following link for more information:

    https://docs.microsoft.com/en-us/aspnet/signalr/overview/guide-to-the-api/handling-connection-lifetime-events#how-to-notify-the-user-about-disconnections

    Best Regards,

    Billy

    Tuesday, November 28, 2017 2:46 AM
  • User-1950972991 posted

    Hello,

    Yes, I have seen this link. I handle following events of Connection on client side:

    • StateChanged -> fired at the start, when connection changes to "Connecting" and then to "Connected" state
    • Reconnected -> never got fired
    • Error -> never got fired
    • Closed -> fire only, when I stop my service and close connection
    • ConnectionSlow  -> never got fired

    So as you can see, I do not get any events, which might signal about broken connection. Also as I said, the heart beat from server to client is coming fine.
    So I'm sure, that connection is not broken by any means.

    Best regards,
    Sergej

    Tuesday, November 28, 2017 1:19 PM
  • User61956409 posted

    Hi Sergej,

    According to your description, it seems that your hub do not push message to client via group broadcast after certain period, but server broadcast (Clients.All.HeartBeat();) can work fine. And based on your test, it seems that your client does not disconnect to hub server after it connected. For troubleshooting the issue, can you share us more details about when and how do you add client to group?

    Besides, you are using single-entry group, do you want to mapping client to connection and broadcast message to specific client?

    With Regards,

    Fei Han

    Thursday, November 30, 2017 7:09 AM
  • User-1950972991 posted

    Hello Fei Han,

    Thank you for your answer!

    Yes, your first paragraph is correct and describes exactly my situation. What I can add to it: I didn't figure out some really good steps to reproduce problem. Sometimes hub works fine whole day, sometimes messages stop coming after hour or two. And it seems, it also doesn't depend on activity: do I send regularly message to a group or not - doesn't seem to matter.

    This is how my clients are added to groups.

    On client side:

    // initialize Connection and create Proxy
    ....
    await Connection.Start();
    await Proxy.Invoke("Register", "Client1");

    On server side the "Register" method of hub:

    public void Register(string clientId) {
      Groups.Add(Context.ConnectionId, clientId);
    }

    Yes, I use single-entry groups to map connections to Client ID (comes out of business logic). In my application I need to send messages to exact clients.

    Thursday, November 30, 2017 2:16 PM
  • User61956409 posted

    Hi Sergej,

    I use single-entry groups to map connections to Client ID (comes out of business logic). In my application I need to send messages to exact clients.

    Based on your test, we can find it is difficult to find the actual issue with group. For mapping a user to the connection id and broadcasting message to specific user, you can try other approach instead of using single-entry group.

    With Regards,

    Fei Han

    Friday, December 1, 2017 8:27 AM
  • User927452105 posted

    Hi Sergej,

    by any chance you did solve this issue or have any solution?

    We're currently facing this, in which we think is an issue from upgrading from 2.2.0 to 2.2.2.

    Tks

    Edgar Durão

    Friday, March 9, 2018 3:13 PM
  • User-1950972991 posted

    Hello Edgar,

    Unfortunately - no. Had no time to continue investigation and had to give up with SignalR and switch to other solution.

    Best regards,

    Sergej.

    Monday, March 12, 2018 7:14 PM
  • User-1131352434 posted

    Hi Edgar,

    I see that the OP never got it sorted so wonder if you did? 

    I have an identical problem using 2.4.1.

    I have an older signalr hub running 1.x in production which has been working flawlessly for several years.  My new project which is almost identical in functionality works fine when published to azure for a while (1-2 days) but then stops distributing to groups.  I had previously been sending direct to clients and switch to single entry groups as I thought that the problem was a connectionId issue - however, the same problem occurs. 

    I've even disabled app pool recycling on the azure host ("disallowOverlappingRotation=true" using Kudo) but this made no difference.

    Thanks

    Phil

    Monday, August 19, 2019 3:31 PM
  • User-1131352434 posted

    Update: I realised that there was a difference between the old application using a 1.x hub and my new 2.x hub in the way that users are handled.

    In the new application, users are added to a group name which contains a period Ie: 0000.0000.0000.0001.  Whereas in the old application user and group names are simply "ASD0123"

    I have removed the full stops and group notification has been working perfectly for over a week.  Sounds to good to be true I know but so far so good …

    Phil

    Tuesday, August 27, 2019 8:00 AM