Repository navigation
Conversation
… dedicated subscription connections Since the RESP3 split (#3264), the dedicated subscription connection cannot be reached via IServer commands, so token-rotation wrappers that keep connections authenticated with periodic AUTH could only cover the interactive connection; the subscription connection's auth lapsed and the server eventually dropped it, losing publications in the window (#3372). IConnectionMultiplexer.ReauthenticateAsync sends AUTH with the currently configured credentials to every established connection: the interactive connection, and the dedicated subscription connection where in-place AUTH is legal (RESP3, or RESP2 with no active subscriptions - subscriber mode rejects AUTH under RESP2, so those connections keep today's lapse-and-reconnect behaviour, which picks up the updated credentials). Multi-group connections refresh every member, not just the active one. Asserted from the server's side in the in-process tests: the AUTH count per connection, including one arriving on a connection with live subscriptions - the connection the issue reports as unreachable.
…hat cannot re-AUTH in place A RESP2 connection in subscriber mode rejects AUTH, so by default it is skipped and relies on the server dropping it when its authentication lapses. On a server that enforces credential expiry, that drop happens at a moment of the server's choosing; AllowReconnect instead recycles the connection now (the same deliberate drop the MOVING handoff uses), so the replacement handshakes with the fresh credentials and restores the subscriptions while the backlog holds new work. Not the default because vanilla password rotation does not invalidate established connections - there, a forced reconnect is an interruption for no benefit.
Existing rotation callers predate ReauthenticateAsync: the
Microsoft.Azure.StackExchangeRedis extension refreshes Entra ID tokens
with server.ExecuteAsync("AUTH", user, password) per connected server,
which only ever reaches the interactive connection. The ad-hoc path
already resolves the command to RedisCommand.AUTH, so recognise it and
re-issue the same command on that server's dedicated subscription
connection wherever ReauthenticateAsync would AUTH it in place (RESP3,
or RESP2 not in subscriber mode) - existing libraries get the
subscription refresh with no code change. Best-effort by design: the
caller's result reflects only their own command.
The ad-hoc IServer AUTH mirror was fire-and-forget with errors discarded, so a failure there was invisible: the caller only sees the interactive reply. Log it as a warning via the configured LoggerFactory. Event 141, since v4 already uses 134-140. Claude-Session: https://claude.ai/code/session_01DUpQ8dy8FLBwADei2VzLmZ
…get, and multi-group The AUTH mirror is wired into each Execute[Async] overload separately, but only one was tested; ReauthenticateAsync with FireAndForget and the multi-group fan-out to standby members had no coverage at all. Claude-Session: https://claude.ai/code/session_01DUpQ8dy8FLBwADei2VzLmZ
…tion; docs RecycleConnection always reported MaintenanceHandoff, whose docs tell consumers to filter it as planned maintenance; a credential-rotation recycle would have been blamed on the server. Add ConnectionFailureType.Reauthentication (13), pass the failure type into RecycleConnection, and treat it like a handoff when deciding whether to abort the backlog. Docs: RESP2 subscription connections are in subscriber mode by default (the configuration channel), partial failure semantics, per-member options for multi-group, and the scope and argument reuse of the ad-hoc AUTH shadow. Claude-Session: https://claude.ai/code/session_01DUpQ8dy8FLBwADei2VzLmZ
…plexer member A new interface member breaks already-compiled third-party implementations at type load. The extension dispatches to ConnectionMultiplexer (via the internal IInternalConnectionMultiplexer, so the test fixture's wrapper still forwards) and to MultiGroupMultiplexer, and throws NotSupportedException otherwise. Claude-Session: https://claude.ai/code/session_01DUpQ8dy8FLBwADei2VzLmZ
…Fast routing fix - Best effort: a failing connection (or multi-group member) is logged (event 142) and skipped rather than faulting the whole call; the count is of connections actually refreshed, and the call only faults if nothing succeeded. - FailFast: a message bound for the subscription connection was refused when the *interactive* connection was down, because PrepareToPushMessageToBridge checked ServerEndPoint.IsConnected; the subscription bridge applies the backlog policy itself against its own state, so skip that check for it. - A whitespace-only password counts as no credentials, as in the handshake. Claude-Session: https://claude.ai/code/session_01DUpQ8dy8FLBwADei2VzLmZ
…alueTuple The library must not reference System.ValueTuple (SanityChecks.ValueTupleNotReferenced). Claude-Session: https://claude.ai/code/session_01DUpQ8dy8FLBwADei2VzLmZ
…iber-mode misjudgement The IServer AUTH shadow shared the caller's argument collection, but can be written after Execute returns, when the caller is free to clear or reuse it - and ExecuteMessage writes the RESP header from Count before enumerating, so a late change could desync the subscription connection. It now takes a copy up front, which also retires the "don't reuse the collection" caveat in the docs. Also document that the RESP2 "is this connection in subscriber mode?" check works from the server's last reported counts, so it can briefly misjudge (a SUBSCRIBE in flight, or only sharded subscriptions, which are counted separately); such a connection gets a rejected in-place AUTH and is not recycled, even with AllowReconnect.
philon-msft
approved these changes
Dec 1, 2026
| Whether a RESP2 subscription connection is in subscriber mode is judged from the subscription counts the server | ||
| last reported, so it can briefly be wrong - for example while a `SUBSCRIBE` is still in flight, or when the | ||
| connection holds only sharded (`SSUBSCRIBE`) subscriptions, which the server counts separately. A connection | ||
| misjudged as idle is sent an in-place `AUTH`, which the server rejects; that is logged as a warning (event id 142) |
Collaborator
There was a problem hiding this comment.
Suggested change
| misjudged as idle is sent an in-place `AUTH`, which the server rejects; that is logged as a warning (event id 142) | |
| misjudged as interactive is sent an in-place `AUTH`, which the server rejects; that is logged as a warning (event id 142) |
?
This branch has not been deployed
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.
Fixes #3372.
Since the RESP3 connection split (#3264), the dedicated subscription connection cannot be reached via
IServercommands —Execute("AUTH", ...)always targets the interactive connection. Wrappers that keep expiring credentials fresh (e.g.Microsoft.Azure.StackExchangeRediswith Entra ID tokens on Azure Managed Redis) therefore only cover the interactive connection; the subscription connection's auth lapses, the server eventually drops it, and publications in the reconnect window are lost.What this adds
ReauthenticateAsync(ReauthenticateOptions, CommandFlags), a public method onConnectionMultiplexerand an extension method onIConnectionMultiplexer. It re-issuesAUTHwith the currently configured credentials (ConfigurationOptions.User/Password) on every established connection of every server, returning the number of connections covered:AUTHis legal — RESP3 (any state), or RESP2 with no active subscriptions. A RESP2 connection with live subscriptions is in subscriber mode, which rejectsAUTH; those are skipped and keep today's lapse-and-reconnect behaviour (documented), which picks up the updated credentials on the reconnect handshake since the multiplexer reads the live options instance.SharedSubscriptionConnection=true): one connection, oneAUTH— no double-send.IConnectionGroup): refreshes every member, not just the active one — a stale standby would otherwise fail over unauthenticated.FailFastrouting fix: withBacklogPolicy.FailFast, a message for an explicitly chosen server was refused whenever that server's interactive connection was down, even when bound for a subscription connection that was up, becausePrepareToPushMessageToBridgecheckedServerEndPoint.IsConnected. The subscription bridge already applies the backlog policy against its own state, so that check is now skipped for subscription-bound messages.ConnectionFailureType.Reauthentication(new enum value): whatConnectionFailedreports whenAllowReconnectrecycles a connection. Previously the shared recycle path always reportedMaintenanceHandoff, which consumers are told to filter as planned maintenance.Ad-hoc
AUTHmirror for existing callers: theMicrosoft.Azure.StackExchangeRedisextension (and anything like it) rotates withserver.ExecuteAsync("AUTH", user, password)per server —IServer-based, confirmed against its source. The ad-hoc path already resolves the command string toRedisCommand.AUTH, so an ad-hocAUTHagainst anIServeris now automatically shadowed onto that server's dedicated subscription connection whereverReauthenticateAsyncwould AUTH it in place (RESP3, or RESP2 not in subscriber mode). Existing wrapper versions get the subscription refresh with no code change. Best-effort: the caller's result reflects only their own command, so if the mirroredAUTHfails, that is logged as a warning (event id 141) viaConfigurationOptions.LoggerFactory, and the subscription connection falls back to authenticating with the configured credentials when it next reconnects; the RESP2 subscriber-mode case is still skipped (that connection would reject it), for whichReauthenticateAsync(AllowReconnect)remains the full answer.The intended rotation pattern (now also in
docs/Authentication.md):Notes from the investigation (details on the issue): detection of an already-deauthenticated subscription connection was already sound — a server-side close is seen immediately by the read loop, and a
-NOAUTHreply to the subscription keepalive ping is treated as a connection failure by the tracer — so this API closes the prevention gap, not a detection one.Validation
AUTHcommands arrived, including one arriving on a connection with live subscriptions, which is the connection the issue reports as unreachable: RESP3 dual (2 connections authed), RESP3 shared (1), RESP2 subscribed (interactive only, subscriber-mode connection untouched, subscription keeps delivering), no-credentials (throws), rejected credentials (faults). Three further tests cover the ad-hoc mirror: RESP3 ad-hocAUTHreaches both connections, RESP2 with an idle (established, unsubscribed) subscription connection reaches both, RESP2 in subscriber mode leaves it alone. A fourth has the server reject the mirroredAUTH, and asserts that the failure is logged and the subscription keeps delivering. The mirror is also checked on each of the fourIServer.Executeoverloads (sync and async, with and without a database), andReauthenticateAsyncis covered withFireAndForgetand on a multi-group connection, where the standby member must be refreshed as well as the active one. Further tests cover best-effort behaviour (a refusing subscription connection, and a group member with no credentials), theFailFastcase with the interactive connection down and the subscription connection up (which fails without the routing fix), whitespace-only passwords, and dispatch of the extension method.Build.csprojRelease build green (all TFMs, analyzers).SortedSetScanLargeZSCAN environment failures also noted on Pub/sub: overlapping subscription restores cannot register on two servers #3353, unrelated.Open questions for review
Interface addition.Now avoided:ReauthenticateAsyncis an extension method onIConnectionMultiplexerrather than an interface member, so existing third-party implementations keep compiling and loading. It dispatches toConnectionMultiplexerand the multi-group multiplexer, and throwsNotSupportedExceptionfor anything else (custom implementations and decorators).RESP2 + active subscriptions: skipped rather than proactively recycled.Now addressed opt-in:ReauthenticateOptions.AllowReconnectrecycles connections that cannot re-AUTH in place (the same deliberate drop the MOVING handoff uses - reconnect handshakes with fresh credentials and restores subscriptions, backlog holding new work meanwhile). Not the default, because vanilla password rotation does not invalidate established connections - there a forced reconnect is an interruption for no benefit; it exists for servers that enforce credential expiry.