Skip to content

test(sentinel): cover +switch-master during rediscovery after a server-side close - #2293

Merged
PavelPashov merged 1 commit into
redis:mainfrom
mplanitzer:test/sentinel-switch-master-during-rediscovery
Nov 16, 2026
Merged

PavelPashov merged 1 commit into
redis:mainfrom
mplanitzer:test/sentinel-switch-master-during-rediscovery

Conversation

@mplanitzer

@mplanitzer mplanitzer commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

#2198 cleans up a connection's failover detector when its stream closes. Its tests close the stream through QUIT. This PR adds a test for a server-side close. 6.0.0 has this bug, and the same cleanup fixes it:

  1. With failoverDetector: true, the server closes the client's connection, for example through a demoted master's CLIENT KILL or a network drop. SentinelConnector.disconnect() does not run.
  2. ioredis reconnects and asks a Sentinel for the master (get-master-addr-by-name).
  3. Sentinels announce +switch-master one after another, so one announcement can reach the old detector during that lookup. In 6.0.0 the old detector is still subscribed. It calls connector.disconnect(), which sets connecting = false, and then connectToNext throws Connection is closed.. The client stays in end permanently, and every later command fails with Connection is closed..

On main, the stream-close cleanup from #2198 stops the old detector at step 1, so the client reaches ready.

Changes

  • test/functional/sentinel.ts: the master mock destroys the client's socket. The Sentinel mock then publishes +switch-master to the open subscriptions while it answers get-master-addr-by-name. The test runs with RESP 2 and RESP 3.
  • SentinelConnector: the comment on the stream close cleanup now also names server-side closes, so that a later change doesn't limit the cleanup to QUIT.

Tests

  • The new test fails on v6.0.0 (expected 'end' to equal 'ready', RESP 2 and 3). It also fails on main when the failoverDetector.cleanup() call is removed from the stream close handler. It passes on main and passed 15 repeated runs.
  • test/functional/sentinel.ts and test/unit/connectors/SentinelConnector: 66 passing (Node 24.22.3, macOS).
  • Prettier and ESLint on the changed files: clean.

Not run: the full suite against a real Redis, and the cluster tests.

6.0.0 is still the latest stable release. Until 6.1.0 ships, 6.0.x users can only avoid this with a custom Connector that cleans up the previous detector in connect().

🤖 Generated with Claude Code


Note

Low Risk
No runtime behavior changes—comment clarification and regression tests only.

Overview
Adds RESP 2 and RESP 3 functional coverage for a Sentinel failover race that previously left the client stuck on end instead of reconnecting to ready.

The new test simulates a server-side master disconnect (socket destroy, not QUIT), then delivers +switch-master to existing failover subscriptions while get-master-addr-by-name is still in flight. It asserts the client recovers to ready, guarding the stream close behavior that cleans up the old FailoverDetector.

SentinelConnector only updates the comment on that close handler to spell out that QUIT and server-side closes both need the same cleanup, so a stale detector cannot call disconnect() mid-reconnect.

Reviewed by Cursor Bugbot for commit 4f6cf05. Bugbot is set up for automated code reviews on this repo. Configure here.

…r-side close

The failover detector of a closed connection must not abort the next
master lookup. Cleaning it up when its stream closes (redis#2198) covers this,
but the existing tests only close the stream through QUIT.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@mplanitzer
mplanitzer marked this pull request as ready for review November 16, 2026 12:30
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-16T12:32:04.956738Z 4f6cf05 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@PavelPashov PavelPashov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, LGTM

@PavelPashov
PavelPashov merged commit d9250d8 into redis:main Nov 16, 2026
22 checks passed
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 6.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants