I’m doing testing with my code, thus the reason for finding these problems!
I’ve noticed that if I have a session running and then terminate that session on the server (using ServerEvents.UnRegisterAsync(request.Id)), the JavaScript client successfully reconnects, however it then connects again so two sessions are created on the server. The first one then drops off after timing out.
I removed the ss-utils.js file and used the native EventSource and this behaviour doesn’t seem to occur?
The SSE Client library has auto reconnection the vanilla EventSource object which it wraps does not. When you unregister you’re removing that SSE connection subscription from the server so it no longer exists & any attempt to access it will result in an error.
Ok, so I’m seeing the following sequence of events:
/event-heartbeat?id=jAFOPfYPkN4x9mBiUm0O
= This request returns 404 not found (session has been deleted from server)
/event-stream?t=1591100656386&channels=0c328a71c14f4a208ebe7bc9672089ed
= This is the reconnection after the session has been deleted. This connection stays open until…
/event-stream?t=1591100656386&channels=0c328a71c14f4a208ebe7bc9672089ed
= The reconnection gets dropped, and this one is opened. This means there are two sessions on the server until the ‘reconnection’ gets timed out.
In certain environments/browsers we have seen SSE sessions stay open and due to operational requirements, there is a need for a user to be able to forcibly remove the session from the admin UI.
Call the unRegisterUrl which is stored on the subscription.ConnectArgs["unRegisterUrl"].
Don’t understand, are you saying that there are zombie server connections that stay forever after the client is gone or that you have operational requirements to kill active connections from the server?
We’ve found zombie sessions that stay when the client has gone. The deletion needs to be done at the server.
I don’t understand the purpose of the UnRegisterAsync function? I thought this would wipe unregister the subscription and the client would gracefully reconnect if still active?
The public endpoint is the unregisterUrl which does call UnRegisterAsync, this is the same URL the client uses to unregister itself.
The graceful way to close a connection is always have the client close their own connection, the client auto reconnects as part of its built in resilience to recover from a broken connection.
IMO I’d be investigating why the zombie connections remain open when the clients have disappeared, if there’s nothing keeping it alive with heartbeats it should be closed by the server. What’s the state of its IEventSubscription? (i.e. LastPulseAt/IsDisposed/Disposing/Response.IsClosed) what happens if you send an event to it, (e.g. PublishRawAsync("\n\n") etc.