Buffer messages to wait for reconnect #697
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Leaving for draft for now, want to double check all retention/removal stuff so there's no memory leak possibility.
Buffer up messages that would be sent to disconnected clients. On client reconnect (just "connect" server side still) check the buffer for the
pid
from the client and re-emit messages.Only keep the messages in the buffer for a fixed amount of seconds (can adjust this maybe with config if needed? Or can use the same timeout as the UI maybe since the user would be prompted to try again anyways if they leave off into the wallet app too long)
Some details on Socket.io handling disconnections:
https://socket.io/docs/v4/tutorial/handling-disconnections
Socket.io does have a built in Connection State Recovery:
https://socket.io/docs/v4/connection-state-recovery
I think this would accomplish what this code does here, however it's not implemented in the Python library VCAuth uses
see: miguelgrinberg/python-socketio#1258
Maybe we shouldn't be using this library? It's a pretty simple wrapper though but could be considerations on handling web sockets in a different way. We do however need to consider that storing in-memory is not what we want forever on VCAuth and need to be able to hook into (DB likely) persistence for multi-pod deployment. The code here should be able to handle that need when we address it.
Update the python socket library too (and other python libraries), and socket.io client JS.