Repository navigation
Drain the reader on stop(), so a message already in its socket is not lost - #42
Merged
Merged
Conversation
…ocket is not lost stop() destroyed the reader socket at once. A reader blocked in BRPOP or BLMOVE whose message the broker had already popped and written to the socket lost it with the socket: a request nobody answered, its caller waiting out its timeout. @imqueue/rpc's graceful shutdown stops the queue on SIGTERM, so every scale-down or rollout went through that path. stop() now drains the reader first, as a broker removed from a cluster already was (CLIENT UNBLOCK on the writer, bounded by IMQ_CONNECTION_QUIT_TIMEOUT, never rejects), then drops the socket. It clears the drain state, so start() after stop() reads again.
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
What does this PR do?
RedisQueue.stop()dropped the reader socket at once. A reader blocked inBRPOP(unsafe delivery) orBLMOVE(safe delivery) whose message the broker had already popped and written to the socket lost it with the socket: a request nobody answers, whose caller waits out its timeout.@imqueue/rpcstops the queue onSIGTERM(service.stop()->imq.stop()), so every scale-down or rollout went through that lossy path.stop()now drains the reader first, exactly as a broker removed from a cluster already is:drain()sendsCLIENT UNBLOCKon the writer, a message already in the socket reaches themessagelisteners, the read loop ends, and only then is the socket dropped. The wait is bounded byIMQ_CONNECTION_QUIT_TIMEOUT(1 s by default) and never rejects.stop()also clears the drain state (draining,reading,readerId), sostart()afterstop()reads again — a host may stop and later restart the same queue to pause reading.destroy()is unchanged: it removes the listeners first, so there is nobody to hand a message to, anddrain()already skips a destroyed queue.ClusteredRedisQueue.stop()needs nothing extra: it calls each host'sstop()concurrently, so the bound is one timeout, not one per broker.Tests:
stop()is called reaches the listener (fails on the oldstop());stop()thenstart()reads the next message.JSDoc of
stop()(onRedisQueueandIMessageQueue),IMQ_CONNECTION_QUIT_TIMEOUT, AGENTS.md and the CHANGELOG (3.10.2) are updated.Type of change
Checklist
npm test).Contribution terms (required)
I grant the project owner the right to license my contribution
commercially, royalty-free, my contribution stays available under
GPL-3.0, I keep my copyright, and I understand I will receive no fee for
it. If I did not agree, I would not be submitting this contribution.