Skip to content

RESP3: share the pub/sub connection by default with servers that only limit push data - #3397

Open
mgravell wants to merge 2 commits into
mainfrom
marc/resp3-auto-shared-subscription
Open

mgravell wants to merge 2 commits into
mainfrom
marc/resp3-auto-shared-subscription

Conversation

@mgravell

@mgravell mgravell commented Dec 3, 2026 •

Copy link
Copy Markdown
Member

#3264 moved RESP3 pub/sub back onto a dedicated connection by default (#3263): Redis applies the pubsub output-buffer limits to everything sent to a subscribed client, replies included, so a large reply on a shared connection gets it killed. redis/redis#16390 changes that for RESP3 clients (only unsent push data counts against pubsub; replies count against normal), and we can assume it ships in the next major. This gets ahead of it: when SharedSubscriptionConnection isn't set, the decision is made per server from the interactive connection's HELLO.

What shares by default

Server Shares? Basis
Redis 9+ (server: redis, no vendor field) yes redis/redis#16390 (assumed; see below)
Garnet (any version) yes no output-buffer limits; measured 1.0.50 to 2.2.14
Dragonfly v1.15+ yes measured v1.15 to v2.1: a 200 MiB reply on a subscribed RESP3 connection is fine
Redis <= 8.x, unstable (255.255.255) no measured 7.4, 8.4, 8.12 (and unstable, which may or may not have #16390)
Valkey (7.2 to 9.2), KeyDB, Redict no measured: all kill a subscribed RESP3 connection on a reply over the pubsub hard limit
AMR, Redis Cloud, Redis Enterprise providers no proxied: HELLO describes the database behind the proxy, not the proxy's limits

An explicit sharedSubscriptionConnection=true|false (or a provider defaulting it to true) still wins, and RESP2 never shares. There's no public API change: the existing option just gains a meaningful "unset".

How

  • ConfigurationOptions.SubscriptionSharing (internal) resolves the option to Always / Never / Auto. Proxied providers set an internal AllowAutomaticSubscriptionSharing => false, so they resolve unset to Never.
  • In Auto, SharesSubscriptionConnection() behaves like Always until the handshake, so nothing opens a dedicated connection that turns out to be unnecessary. The HELLO processor then records the verdict (SubscriptionSharingPolicy) before anything queued behind the handshake is written.
  • A server that doesn't qualify takes the existing "asked for RESP3, got RESP2" path (RESP3→RESP2 reconnect can replay SUBSCRIBE  onto the interactive connection, permanently poisoning it #3154): queued subscription messages are rerouted, and the dedicated connection is opened late.
  • The decision is latched per endpoint, and only moves towards dedicated. A reconnect that finds a server that no longer qualifies (failover to an older node, a RESP2 handshake) falls back for good. An endpoint that's gone dedicated never switches back to sharing mid-session, because moving pub/sub between connections is where the races live.

Variant detection

Along the way I checked that every variant is detected, against real servers for both protocols, and fixed two gaps:

  • Dragonfly v1.0 reports dfly_version (not dragonfly_version) and has no HELLO, so it was detected as plain Redis.
  • Valkey 7.2 says server: redis in HELLO but reports its own version (7.2.16, where INFO has redis_version:7.2.4). HELLO's version is now only taken from the interactive connection, where INFO follows and has the final say. Before, a subscription connection's HELLO could land later and overwrite it (Detected server version is non-deterministic on Valkey since 3.4.0 #3278 again, for the one Valkey line that says redis).

ProductVariantUnitTests now covers Dragonfly (both spellings), Redict, KeyDB and Valkey 7.2's HELLO shape. That includes a deterministic subscription-reconnect check, which fails without the fix.

Testing

  • SubscriptionSharingUnitTests: the policy table, mode resolution, and connection shape per server shape (in-process server with faked HELLO replies). Also: RESP2 downgrade, a subscription queued before the handshake landing on the right connection, the fallback-and-stay-dedicated latch, and the proxied-provider opt-out.
  • PubSubOutputBufferTests gains a default-setting variant. ClientKill, ConnectUsesSingleSocket and DedicatedThreadsTests now set the option explicitly rather than relying on "unset means dedicated", which stops being true on Redis 9.
  • Full net10.0 suite against the docker topology: no new failures compared with main.
  • Real servers: Garnet and Dragonfly run on one connection and survive a 40 MiB reply while subscribed. Redis 8.12 and Valkey 9.2 get two connections. Forcing sharing on Redis 8.12 still kills the connection, as expected.

redis/redis#16390 itself is not merged, and I haven't run a build of it, so the Redis 9 row is an assumption about what ships. Until a 9.x exists, nothing real qualifies on that row.

Before merging

Don't merge this until redis/redis#16390 is merged and the Redis 9 assumption has been checked against it:

Release note

Under RESP3, when SharedSubscriptionConnection is not set, pub/sub now shares the interactive connection with servers known to apply pub/sub output-buffer limits only to push data: Redis 9+ (redis/redis#16390), Garnet, and Dragonfly v1.15+. Other servers, and AMR / Redis Cloud / Redis Enterprise, keep a dedicated subscription connection. Set the option explicitly to choose for yourself. Also: Dragonfly v1.0 is now detected, and Valkey 7.2's Redis API version is no longer overwritten by its HELLO version.

Checklist

  • I fully and freely contribute this code in accordance with the project license (and am legally able to do so)
  • I take responsibility for this contribution's quality and correctness, including any portions produced with AI assistance (see CONTRIBUTING.md).

… limit push data

When SharedSubscriptionConnection isn't set, decide per server from the interactive
HELLO: share with Redis 9+ (redis/redis#16390), Garnet, and Dragonfly v1.15+; keep a
dedicated subscription connection everywhere else (Redis <= 8.x and unstable builds,
Valkey, KeyDB, Redict) and for proxied deployments (AMR, Redis Cloud, Enterprise).
A server that stops qualifying on reconnect falls back to dedicated for good.

Also: detect Dragonfly v1.0 (dfly_version), and only take HELLO's version from the
interactive connection, so Valkey 7.2 (server: redis, its own version) can't overwrite
INFO's redis_version from a subscription reconnect.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant