Skip to content
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

Merged
merged 8 commits into from
Sep 15, 2020

Conversation

rennokki
Copy link
Collaborator

@rennokki rennokki commented Sep 12, 2020

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

@rennokki rennokki changed the base branch from master to 2.x September 12, 2020 14:50
@rennokki rennokki changed the title [feature] PCNTL signals for soft-close of connections [feature] PCNTL signals into soft-close of connections for Redis horizontal replication Sep 12, 2020
@codecov-commenter
Copy link

codecov-commenter commented Sep 14, 2020

Codecov Report

Merging #523 into 2.x will increase coverage by 0.10%.
The diff coverage is 90.26%.

Impacted file tree graph

@@            Coverage Diff             @@
##              2.x     #523      +/-   ##
==========================================
+ Coverage   88.22%   88.32%   +0.10%     
==========================================
  Files          50       52       +2     
  Lines        1316     1413      +97     
==========================================
+ Hits         1161     1248      +87     
- Misses        155      165      +10     
Impacted Files Coverage Δ
src/Server/MockableConnection.php 66.66% <66.66%> (ø)
src/Console/Commands/StartServer.php 87.35% <80.76%> (-1.88%) ⬇️
src/ChannelManagers/RedisChannelManager.php 87.12% <91.66%> (+0.96%) ⬆️
src/ChannelManagers/LocalChannelManager.php 97.89% <100.00%> (+0.52%) ⬆️
src/Helpers.php 100.00% <100.00%> (ø)
...c/Server/Messages/PusherChannelProtocolMessage.php 100.00% <100.00%> (ø)
src/Server/WebSocketHandler.php 100.00% <100.00%> (ø)
src/Statistics/Collectors/RedisCollector.php 95.70% <100.00%> (-0.11%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1dcf853...980f927. Read the comment docs.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants