fix(server): preserve existing connections after requirepass changes#3443
Open
aviralgarg05 wants to merge 2 commits intoapache:unstablefrom
Open
fix(server): preserve existing connections after requirepass changes#3443aviralgarg05 wants to merge 2 commits intoapache:unstablefrom
aviralgarg05 wants to merge 2 commits intoapache:unstablefrom
Conversation
git-hulk
reviewed
Apr 10, 2026
git-hulk
requested changes
Apr 10, 2026
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.
Description
This fixes a Redis Sentinel compatibility issue reported in #3267.
When Kvrocks accepted a connection while
requirepasswas still empty, it did not immediately mark that connection as authenticated. Instead, it deferred assigning the default namespace/admin context until the connection sent its first command.That differs from Redis behavior.
In practice, this created a race with older Sentinel versions. Sentinel could establish a connection to the master before
auth-passwas configured, but only send its first probe afterward. Redis continues to allow that already-open connection to operate, while Kvrocks responded withNOAUTH. As a result, Sentinel could temporarily treat the master as down and fail to discover replicas until a reset or restart forced a fresh connection cycle.This change fixes the behavior at the source:
requirepassis later set continue to behave like Redis.requirepassis set still require authentication as expected.Files changed
Why this is safe
The change is limited to the connection initialization path and only affects connections created while the server is running without a password configured.
It does not relax authentication for:
requirepasssetrequirepassis enabledSo the fix restores Redis-compatible semantics without changing the normal protected path.
Test coverage
Added a regression test that verifies:
CONFIG SET requirepass ...remains usablerequirepassis set receivesNOAUTHValidation
Ran:
./x.py build -j 8./x.py format./x.py check formatgo test -timeout=1800s -run 'TestNoAuth|TestAuth' ./unit/auth -binPath=/Users/aviralgarg/Everything/kvrocks/build/kvrocks -cliPath=redis-cli -workspace=/Users/aviralgarg/Everything/kvrocks/tests/gocase/workspaceThe auth test suite was run 3 times and passed each time.
I also manually verified the repro condition:
requirepasswas enabled received-NOAUTH+PONGNotes
Two repo-wide checks are currently blocked by the local environment rather than this change:
./x.py check tidyrun-clang-tidyfrom local LLVM, it reports existing unrelated tidy failures outside this patch./x.py check golangci-lintgolangci-lintis2.8.0, while the repo requires2.9.0+