fix(cluster): replay every subscription handler to a joining server - #30
Merged
Merged
Conversation
Contributor
|
All contributors have signed the @imqueue Contribution Terms. ✅ |
Mikhus
approved these changes
Sep 14, 2026
Mikhus
left a comment
Member
There was a problem hiding this comment.
Thank you for the contribution. This is really good change. Please, sign CLA so I can merge it
Member
Author
|
I have read the CLA Document and I hereby sign the CLA |
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?
Closes #29
ClusteredRedisQueueremembered one{ channel, handler }pair, so eachsubscribe()overwrote the previous one. Handlers still reached the serversalready in the cluster — which is why this stays invisible while membership is
stable — but a server joining later was replayed only the last-registered
handler.
With one handler carrying business events and another carrying cache
invalidation, such a host serves the second and silently drops the first. The
socket stays subscribed, the publisher still sees a subscriber, RPC is
unaffected and health checks pass, so nothing surfaces the loss.
Every registration is now remembered and installed, in registration order,
including the same function registered twice (
subscribe()stays additive asIMessageQueuedocuments). The livesubscribe()path and the catch-up for ajoining server became one serialised operation per host, so a handler cannot be
installed twice.
Three smaller fixes fall out of the same code:
rejection — a process exit on current Node defaults. It is now consumed
where it is already reported.
start()could be left unstarted when the cluster wasstarted a microtask later, because the decision to start was taken inside a
deferred body whose promise had already been cached.
destroy()now closes admission synchronously, settles asend()parkedwaiting for its first server, and attempts every cleanup task independently so
one failure cannot strand the rest.
Type of change
Checklist
npm test).How it was verified
npm test— 413 pass.npm run test-integration— 6 specs drive a real broker and assertdeliveries rather than mocked calls. They skip with a reason where no broker
answers, and
npm testdoes not run them, so CI is unaffected.no-serialisation variant and confirming it fails there. Every guard was
mutation-tested individually: removing any one of them fails at least one
test.
registrations carried one handler; it now carries both.
Note on release level
Not a patch.
subscribe()now rejects a bad channel on an empty cluster where itpreviously resolved,
subscribe()/unsubscribe()serialise per host, and adestroyed instance rejects work it used to accept. All are in
CHANGELOG.mdunder
### Changed.Known limitation, unchanged by this PR
An
imq.start()already in flight cannot be cancelled, so astop()arrivingmid-start can still leave a stopped cluster with a started host. Verified
present in v3.5.1 as well; out of scope here.
Contribution terms (required)