-
When clients connect to my hub I can see everything initially working:
However on the client side (blazor wasm) I can see that after a while, it re-attempts the connection as it never receives a "keep-alive" ping from the server. This surfaces as my On the client side (blazor wasm) I have configured the client connection like so:
On the server side things are a little more "non standard" as I am calling AddSignalR() in a child container built for the tenant, and MapHub() is called in a fork of the root IApplicationBuilder built for that tenant.
I am able to issue messages from the server to the connected clients absolutely fine. So clients can connect, and they can receive messages. The only thing that doesn't appear to be working, is the thing that should be "pinging" the clients to keep them alive. Based on these settings I would expect to see a Ping sent from the server close to every 10 seconds but I don't see any Ping messages being issued from the server at all.. I think this is something to do with the fact that SignalR services are being added to the child container, child IApplicationbuilder but I am not sure. I have looked through the code but it is not clear to me which class is responsible for sending Ping() messages to clients, and what it's dependencies are? Is anyone able to give me a pointer? I have configured logging to trace level on the server (and client) for the following and there is no log message indicating any ping message being sent, and I can't see a ping in fiddler either.
|
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 12 replies
-
What version of the client are you using? Can you see the client sending pings? |
Beta Was this translation helpful? Give feedback.
-
Not within the chrome network tab no. All I see is that client negotiates a connection via web socket. It then connects via web socket and those connections stay in a "pending" state (should they?") - here is the output, as you can see I am connecting to two different hubs here and they both exhibit the same problem: Later on, after a period of no activity, I see my "retry policy" kick in on the client side, and the process repeats with the sae log output again - i.e the client negotiates a new connection. On the server on each attempt - I see the user is connected (The Hub's OnConnectedAsync method fires) and all looks well. However - it also appears that when the server is pushing messages to these "connected" clients - It is pushing 5 messages in a row. Only every other one makes it to the client. This behaviour appears consistent - Message 1, 3 and 5 are received by the client, message 2 and 4 never make it. On the server side I can see that all 5 messages are sent to the user via the hub and all looks fine from that perspective. |
Beta Was this translation helpful? Give feedback.
-
The following hopefully shows more fully what I am seeing:
After 4 - 5 mins, the websocket connection was closed, and the client IRetryPolicy then creates a new one with the same symptoms. For this example, I had increased the timeouts on the server and the client a bit to give me some more time to capture what was going on. Server:
Client:
The client side |
Beta Was this translation helpful? Give feedback.
-
Ok so my issue turned out to be that I was not getting the same instance of This is something I'll need to fix in terms of how that service is resolved from child containers. |
Beta Was this translation helpful? Give feedback.
Ok so my issue turned out to be that I was not getting the same instance of
IHostApplicationLifetime
from the tenants child container as was registered in the application container - tenants were getting their own singleton instances of this. On those "per tenant" instances, they were never having the lifetime event called, and so the background ping method was never initiated.https://github.com/dotnet/runtime/blob/6072e4d3a7a2a1493f514cdf4be75a3d56580e84/src/libraries/Microsoft.Extensions.Hosting/src/HostBuilder.cs#L215
This is something I'll need to fix in terms of how that service is resolved from child containers.