Repository navigation
Fix graceful shutdown example flakiness - #1507
Merged
Merged
Conversation
When shutdown cancels a pgx query during a socket write, the driver can return an I/O timeout instead of wrapping `context.Canceled`. The scheduler logs this expected cancellation as an error, and the shutdown examples' stdout loggers make their output checks flaky. Check the scheduler's service context before reporting failed passes and exit when it is canceled. Route both shutdown examples' diagnostic logs to stderr so asynchronous diagnostics do not alter expected output. Cover write timeout errors after parent cancellation and explicit stop, and preserve logging for database errors with an active context.
brandur
approved these changes
Oct 14, 2026
Comment on lines
+135
to
+139
| // Cancellation can surface as a driver-specific error, like a | ||
| // socket write timeout, instead of wrapping context.Canceled. | ||
| if ctx.Err() != nil { | ||
| return | ||
| } |
Contributor
There was a problem hiding this comment.
Wouldn't this generally always take precedent before we hit the context.Canceled check below?
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.
The Go 1.26/Postgres 18 job on #1504 fails intermittently because
Example_gracefulShutdownprints an unexpected scheduler error. When shutdown interrupts a pgx query write, the driver can returnwrite failed: ... i/o timeoutinstead of an error wrappingcontext.Canceled, so the scheduler's cancellation filter treats it as a database failure.Check the scheduler's service context before logging a failed pass so a canceled scheduler exits quietly, while database errors with a live context still log. Send both shutdown examples' diagnostic logs to stderr so asynchronous logs cannot alter their expected stdout.
Add deterministic regression coverage for write timeouts after parent context cancellation and explicit
Stop, plus a live context case that preserves database error logging.