Detect advisory locks at query_parser = auto on single-primary clusters - #1408
Open
mhenrixon wants to merge 1 commit into
Open
Detect advisory locks at query_parser = auto on single-primary clusters#1408mhenrixon wants to merge 1 commit into
mhenrixon wants to merge 1 commit into
Conversation
At the auto level (the default), the regex fallback in RegexParser::use_parser matched only the base session-control command set. On clusters where nothing else engages the query parser — a single primary, no sharding, no replicas — advisory lock statements therefore bypassed the parser entirely: the client was never pinned to its backend, pg_advisory_unlock could route to a different server connection (the WARNING is silently swallowed), and the session lock stranded on the pooled backend until it happened to be closed. Sharded and read/write-split clusters were unaffected because the parser is already fully engaged there. Match the advisory regex set (base + advisory) at auto, so session advisory locks pin, unlock correctly, and get cleaned up by pg_advisory_unlock_all when a client disconnects mid-hold. Fixes pgdogdev#1407
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 #1407.
Root cause
Debugging #1407 against a local build showed the leaked locks were a detection problem, not a cleanup problem. At
query_parser = "auto"(the default),RegexParser::use_parsermatches only the base session-control command set —CMD_RE, notCMD_RE_ADVISORY. On a cluster where nothing else engages the query parser (single primary, no sharding, no replicas —router_needed()is false), advisory lock statements therefore bypass the parser entirely:pg_advisory_unlockcan route to a different server connection (Postgres emits aWARNINGthe app never sees) and the session lock strands on the pooled backend;pg_advisory_unlock_all()cleanup never runs —[cleanup] no cleanup neededwithAdvisoryLocks { locks: {} }in the debug log.Sharded and read/write-split clusters are unaffected because the parser is already fully engaged for routing.
Fix
Match the advisory regex set (base + advisory patterns) at
autoas well, so session advisory locks pin, unlock on the right backend, and get cleaned up on disconnect. The regex gate still only enables the per-request parse for matching statements, so plain traffic is untouched.Verification
test_advisory_lock_auto_level(plus the existing advisory tests all pass).auto), client runsSELECT pg_try_advisory_lock(424242, 0)and is SIGKILLed while holding the lock.pg_lockson the server).[cleanup] running 3 cleanup queries→SELECT pg_advisory_unlock_all()and the lock is released.