Reset server-side state when reusing persistent connections#2825
Open
KentarouTakeda wants to merge 1 commit intophpredis:developfrom
Open
Reset server-side state when reusing persistent connections#2825KentarouTakeda wants to merge 1 commit intophpredis:developfrom
KentarouTakeda wants to merge 1 commit intophpredis:developfrom
Conversation
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 pooled connection is retrieved via
pconnect, server-side state from the previous request—SELECT,WATCH,CLIENT SETNAME, etc.—carries over. This causes reads and writes to go to the wrong database, stale watches to break transactions, and other subtle failures.Fixes #1920. Related: #428.
Solution
Add the Redis 6.2
RESETcommand to theredis_sock_check_liveness()pipeline so that all server-side state is cleared on pool retrieval.RESET→AUTH→ECHO(prepended to the existing liveness check)-ERRresponse is cached inConnectionPool.reset_unsupported; subsequent retrievals skip the command entirelyerrorstatssection was introduced in 6.2—the same version that addedRESET—so no per-error counter is incremented on older servers; after the flag is cached the command is not sent at allWhy RESET
DISCARD+UNWATCH+SELECT 0+…)RESET6.2 adoption
RESETwas added in Redis 6.2 (February 2021). Major managed services already provide it:On pre-6.2 servers,
RESETreturns-ERRbut the connection stays alive. After the flag is cached the additional cost drops to zero.Changes
common.h— addRESP_RESET_CMDconstant; addreset_unsupportedfield toConnectionPoollibrary.c— send and consumeRESETinredis_sock_check_liveness(); passConnectionPool *to the functiontests/RedisTest.php— three regression tests coveringSELECT,WATCH, andCLIENT SETNAMEstate leaks