Repository navigation
fix: guarantee QoS 1 buffered messages deliver before live messages on reconnect - #4
Open
amitgujarpatil wants to merge 1 commit into
Conversation
…n reconnect When a client reconnects with cleanSession=false, restoreSubs wires up mqemitter listeners before emptyQueue drains the persistence store. This allowed live messages to reach the client before buffered ones, breaking delivery order for QoS 1 sessions. Fix: set client._drainingQueue=true at the start of emptyQueue so that deliverQoS pushes incoming live packets into client._liveQueue instead of writing them immediately. Once the persistence drain finishes, _drainingQueue is cleared and _liveQueue is flushed in order. client.close() drains any held callbacks so mqemitter never stalls. Also adds aedes-persistence-redis v11.2.2 as a dependency. This version supports Redis Cluster via opts.cluster (ioredis), resolving the prior blocker that prevented persistent sessions in clustered deployments. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
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.
Summary
aedes-persistence-redisv11.2.2 as a dependency, which now supports Redis Cluster viaopts.cluster(ioredis)Root Cause
The
connectActionspipeline runs in this order:restoreSubsregisters mqemitter listeners — live messages start flowing immediately.emptyQueuedrains the persistence store only after that, so buffered messages arrived after live ones.Fix
Three changes to
lib/client.jsandlib/handlers/connect.js:client._drainingQueueflag (constructor) —falseby defaultdeliverQoSgate — when_drainingQueueistrue, incoming live QoS packets are pushed toclient._liveQueueinstead of written immediatelyemptyQueue— before/after drain:_drainingQueue = truebefore streaming from persistenceafterDraincallback clears the flag and flushes_liveQueuein orderclient.close()— drains_liveQueuecallbacks so mqemitter never stalls if the client closes mid-drainMessage flow after fix:
aedes-persistence-redis
Previous comment in the server blocked this with "does not support connecting to the clustered redis". v11.2.2 resolves this — it accepts
opts.clusterand internally uses ioredis Cluster mode.Test plan
cleanSession=false, QoS 1 subscriptionclean=truesession — verify unaffected (_drainingQueueis set and cleared with empty stream)🤖 Generated with Claude Code