Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
1 of 2 tasks
r002 opened this issue Aug 17, 2020 · 2 comments
Open
1 of 2 tasks

Comments

@r002
Copy link
Owner

r002 commented Aug 17, 2020

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:

  • Put the clientMap into a beautiful table.
  • Add the Prune zombie clients! button & function to the admin GUI.
@r002
Copy link
Owner Author

r002 commented Aug 19, 2020

Today's Progress

  • "Broadcast Flash Message" function now works. From the Admin GUI, I can blast flash messages to all connected clients.
  • "Request heartbeat from all clients" function now works. From the Admin GUI, I can request all connected clients heartbeat back to the server. Here's an example:

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

  • I need to implement a loop on the server that periodically runs when clientMap.size() > 0 that evicts stale connections. Update the status field for each client in the server's clientMap. Do the "stale" vs "fresh" ms delta calculation on the server.

r002 added a commit that referenced this issue Aug 19, 2020
…he Admin GUI. Add 'Broadcast Flash Message' fxn on the Admin GUI. Add 'Request heartbeat from all clients' fxn on the Admin GUI.
r002 added a commit that referenced this issue Aug 21, 2020
…n if 'clientMap.size>0'. The loops detect and evict stale connections. Their values are driven by .env config.
@r002
Copy link
Owner Author

r002 commented Aug 21, 2020

Next

  • Fix: clientMap should not be broadcasted on every heartbeat! If two clients are connected, then clientMap will be broadcasted to all endpoints every REFRESH_INTERVAL.

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?)

r002 added a commit that referenced this issue Aug 23, 2020
… time a client is added or removed, or if the refreshLoop runs. The 'clientMap' is no longer broadcast on every client heartbeat.
r002 added a commit that referenced this issue Sep 1, 2020
…/js/config.js'. Update this to be driven from server-side config later.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant