Skip to content

Keep discarded cached Parses out of the pending queue - #135

Merged
gh-worker-dd-mergequeue-cf854d[bot] merged 2 commits into
DataDog:mainfrom
perfloop-oss:perfloop-pr-open-k9y5eq59zf
Dec 2, 2026
Merged

gh-worker-dd-mergequeue-cf854d[bot] merged 2 commits into
DataDog:mainfrom
perfloop-oss:perfloop-pr-open-k9y5eq59zf

Conversation

@perfloop-agent

Copy link
Copy Markdown
Contributor

What does this PR do?

An extended-query pipeline can lose a valid prepared statement after an error and rollback to a savepoint: a Bind of s_other after COMMIT fails with SQLSTATE 26000. This change prevents a discarded, backend-cached Parse from consuming the next valid statement's confirmation.

Motivation

With SELECT 1 already cached, a failing message followed by Parse(s_reuse, SELECT 1) and Sync leaves s_reuse pending. After ROLLBACK TO SAVEPOINT, parsing s_other as SELECT 2 incorrectly confirms s_reuse instead. A Bind inside the transaction can still find s_other in the pending queue; COMMIT clears that queue and exposes the missing confirmation.

Move the cached-path return outside the success-only branch: discarded Parses are neither queued nor forwarded, while successful cache hits still produce ParseComplete. The next confirmation then belongs to s_other. This covers named statements with automatic caching off or on, and automatically cached unnamed statements.

How did you test it?

Focused session Go tests passed on Go 1.26.0 and Go 1.27.4 with race detection. The regression in pkg/session/discarded_parse_pending_queue_test.go fails without the fix and passes with it across all 12 cache-mode and earlier-error combinations. Scoped CONTRIBUTING checks pass.

test/integration/discarded_parse_test.go now binds after COMMIT and compiles with race detection. PostgreSQL-backed integration execution remains unvalidated and is left to target CI.

AI assistance

Implemented with Perfloop.

Case and evidence


Made by Perfloop. Human sponsor: Tomás Senart.

Exercise pending-statement confirmation across savepoint recovery and bind the new statement after commit so discarded pending entries cannot mask a lost definition.

Signed-off-by: Perfloop Agent <[email protected]>
An earlier buffered error makes PostgreSQL ignore a cached Parse until Sync. Do not queue or forward that Parse: in a transaction held across savepoint recovery it would consume the next valid ParseComplete.

Signed-off-by: Perfloop Agent <[email protected]>
@perfloop-agent
perfloop-agent requested review from a team as code owners December 2, 2026 00:29
@perfloop-agent
perfloop-agent requested a review from VashDD December 2, 2026 00:29
@tsenart

tsenart commented Dec 2, 2026

Copy link
Copy Markdown

Hi, I'm Tomás, I build Perfloop. I approved this contribution and will handle review feedback here.

@jhinds, this builds on the cached-Parse shortcut in handleRecordNewPreparedStmt. It keeps a Parse that is discarded after an earlier error out of the pending queue. We found it while hunting correctness bugs with Perfloop. We also ran go test -tags=integration -race ./test/integration against PostgreSQL 14: the new test fails without the fix, and the whole suite passes with it. We've had over 190 changes merged in projects like CoreDNS, Skipper, Distribution, and more, plus issues fixed from our reports.

If you'd like anything in this patch changed, just let me know and I'll update it.

@jhinds

jhinds commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

@tsenart thanks for the contribution! let me run the tests

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants