r002 / rittr

A Robertlandian take on Twitter...
0 stars 0 forks source link

Build Admin feature that requests heartbeat from all connected clients. #22

Open r002 opened 4 years ago

r002 commented 4 years ago

Problem

SSE doesn't automatically detect if a client has died. This means over time our clientMap will be polluted with zombie clients. Cycling the server will request an auto-reconnect (supported by SSE out of the box) but we need another way to prune dead clients from clientMap.

Solution

Add a REST endpoint that, when hit, requests a heartbeat from all connected clients that are still alive. Any client that doesn't pong back within X seconds will then be removed from clientMap. [Should this REST endpoint be a GET or POST?]


Tasks:

r002 commented 4 years ago

Today's Progress

image

Here, I just clicked on the "Request heartbeat..." link and Connections No 3 & 4 updated their "Last Heartbeat" timestamps. Conn No 1 & 2 didn't update though because those clients have been closed (either due to connectivity loss of the Chrome tab was force-closed, etc).


Next Steps

r002 commented 4 years ago

Next

Not a bug: clientMap on the Admin GUI is 10 seconds behind the ts that's being broadcast to all client endpoints. Investigate and fix.

clientMap should only be broadcasted to all endpoints in the following cases:

  1. The "refresh_map" loop is firing.
  2. Client is added? (Or wait until the loop fires?)
  3. Client is removed? (Or wait until the loop fires?)