This repository was archived by the owner on Feb 7, 2024. It is now read-only.
[feature] PCNTL signals into soft-close of connections for Redis horizontal replication #523
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.
Since the horizontal replication stores some of the presence channels data and the connection IDs in Redis, if the server abruptly closes, the Redis data might still be persistent.
In this PR, I came up with a first gate on which upon SIGINT/SIGTERM, the entire connections list gets closed, but not before the server marks itself as being unable to accept new connections, while the current connections are closed and the process finally terminates.
This is definitely not ideal but as the first gate on termination protection, it should be enough until I come up with another idea on how to expire the data within the Redis sets between ping-pongs (so if the user doesn't ping anymore, it will let the Redis DB invalidate the key associated to that connection).
Additionally, since whenever one server gets interrupted and loses the local data and Redis still keep tracking of the old data unless the PCNTL signal gets read properly, it will loop through the expired connections from the sorted list in Redis, and will expire all connections that didn't pong in the last 2 minutes (120 seconds) according to the pusher protocol: https://pusher.com/docs/channels/library_auth_reference/pusher-websockets-protocol#recommendations-for-client-libraries