Repository navigation
fix(redis): read the reconciliation backlog on its own connection - #6
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
A subscriber reconnecting with a Last-Event-ID makes
reconciliate()await aLRANGE key -size -1of the whole stored list on the command connection. The watchdog pings that same connection underreadTimeout, and a Redis connection answers in order, so the PONG waits behind the LRANGE reply. With a list of 30000 updates of about 4 KB each, the reply takes more than 5 seconds to stream (clue/redis-protocol re-parses the multi-bulk from its start on every chunk), the timeout rejects,Hub::die()stops the hub, every EventSource reconnects with its Last-Event-ID and the loop repeats. This is what a hub run withpingInterval=2&readTimeout=5did on a live deployment: four replicas each dying about 7 seconds after their start, 455 exits in 21 minutes, untilpingInterval=0was set back.Reproduced on 0.5.1 with Redis 7.2.4: a 30000-entry list and one subscriber reconnecting with a Last-Event-ID end the hub with
TimeoutException: Timed out after 5 secondsabout 9 seconds after boot, while an empty list, a subscriber without Last-Event-ID orreadTimeout=0never do. A similar scenario, three subscribers reconnecting at once on a 35 MB list, ends 0.5 the same way, so the timeout on the command connection predates bpolaszek#52. A publish landing during a reconciliation waited behind the same LRANGE.The reconciliation reads now go through a third lazy client, so the pinged connection never waits behind a bulk reply.
RedisTransporttakes it as an optional$readerargument defaulting to the command client, and the factory creates it. The watchdog is unchanged: the command and the subscription connections are both still pinged underreadTimeout. The reader is not pinged, the lazy client closes it after its idle period, and a reconciliation that fails no longer ends the hub.Integration tests against a real Redis (
FREDDIE_TEST_REDIS_DSN, exported by the integration job of the CI, skipped when unset) fail on the current code for the head-of-line blocked PONG and for a hub dying on a busy but healthy connection, and pass with the fix: the PONG answered under a second during a reconciliation, two concurrent reconciliations completing without a death, a paused Redis still ending the hub withinpingInterval + readTimeout, a killed subscription connection still ending it at once, the subscribed connection still answering["pong", ""], andpingInterval=0still disabling the watchdog. A unit test checks that the factory creates the third client.