fix: Queue batch commands to backlog during MOVED reconnection#3134
Open
advaMosh wants to merge 2 commits into
Open
fix: Queue batch commands to backlog during MOVED reconnection#3134advaMosh wants to merge 2 commits into
advaMosh wants to merge 2 commits into
Conversation
When a MOVED-to-same-endpoint triggers reconnection (PR StackExchange#3003), batch commands issued during the ~50-100ms reconnection window fail immediately with NoConnectionAvailable. This is because: 1. RedisBatch.Execute() calls SelectServer() which returns null for disconnected/reconnecting servers. 2. PhysicalBridge.TryEnqueue() returns false when !IsConnected, unlike TryWriteAsync/TryWriteSync which queue to the backlog. This creates an inconsistency where individual async commands succeed (queued via BacklogPolicy) but batch commands throw during the same reconnection window. Fix: - RedisBatch.Execute(): When SelectServer returns null and BacklogPolicy.QueueWhileDisconnected is enabled, retry with allowDisconnected=true to find the server endpoint. - PhysicalBridge.TryEnqueue(): When disconnected/reconnecting and BacklogPolicy.QueueWhileDisconnected is enabled, queue messages to the backlog instead of returning false. This matches the existing behavior of individual command paths and ensures batch commands are transparently queued and sent after reconnection completes. Tested with proxy redirect scenario (MOVED-to-same-endpoint + disconnect): - Before: 1-3 NoConnectionAvailable errors per MOVED redirect - After: 0 errors, batch waits for reconnection via backlog
advaMosh
force-pushed
the
fix/batch-backlog-during-reconnect
branch
2 times, most recently
from
July 21, 2026 11:34
4d15422 to
f33c283
Compare
mgravell
approved these changes
Jul 21, 2026
Add two integration tests verifying batch commands are queued to the backlog during MOVED-to-same-endpoint reconnection: - MovedToSameEndpoint_BatchCommands_QueuedDuringReconnect: Verifies that a batch containing a MOVED-triggering command completes successfully after reconnection (commands queued to backlog). - MovedToSameEndpoint_SubsequentBatch_QueuedDuringReconnect: Verifies that a second batch issued during the reconnection window is queued rather than throwing NoConnectionAvailable (fire-and-forget scenario).
advaMosh
force-pushed
the
fix/batch-backlog-during-reconnect
branch
from
July 21, 2026 12:10
f33c283 to
917ae81
Compare
Author
|
hey @mgravell , thank you for the quick response ! |
Collaborator
|
The CI has a bit of noise, sadly. I've poked it. I'll do another eyeball tomorrow, but there's no reason to delay this any - we tend to build fairly regularly when there's reason to. |
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.
Problem
When a MOVED-to-same-endpoint triggers reconnection (as implemented in PR #3003), batch commands (
IBatch) issued during the ~50-100ms reconnection window fail immediately withRedisConnectionException: NoConnectionAvailable. This is because:RedisBatch.Execute()callsSelectServer()which returns null for disconnected/reconnecting servers.PhysicalBridge.TryEnqueue()returns false when!IsConnected, unlikeTryWriteAsync/TryWriteSyncwhich queue to the backlog viaQueueOrFailMessage()→BacklogEnqueue().This creates an inconsistency: individual async commands (e.g.
db.StringSetAsync()) are queued and succeed after reconnection, but batch commands throw immediately during the same reconnection window.Impact
IBatchsee 1-3RedisConnectionExceptionerrors per MOVED redirect, while individual async commands see zero errors in the same scenario.Fix
RedisBatch.Execute(): WhenSelectServer()returns null andBacklogPolicy.QueueWhileDisconnectedis enabled, retry withallowDisconnected: trueto locate the server endpoint. This mirrors the pattern already used inPrepareToPushMessageToBridge().PhysicalBridge.TryEnqueue(): When!IsConnected || NeedsReconnectandBacklogPolicy.QueueWhileDisconnectedis enabled, queue messages to the backlog instead of returning false. This matches the existing behavior ofTryWriteSync()andTryWriteAsync()for individual commands.Testing
Tested with a proxy that sends MOVED-to-same-endpoint followed by connection close:
NoConnectionAvailableerrors per redirect event (batch.Execute throws during ~50-100ms reconnection window)The fix only activates when
BacklogPolicy.QueueWhileDisconnectedis true (the default), preserving existing behavior for users who have disabled backlog queuing.Related