Skip to content

Fix graceful shutdown example flakiness - #1507

Merged
brandur merged 1 commit into
masterfrom
bg/fix-graceful-shutdown-example
Oct 15, 2026
Merged

brandur merged 1 commit into
masterfrom
bg/fix-graceful-shutdown-example

Conversation

@bgentry

@bgentry bgentry commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

The Go 1.26/Postgres 18 job on #1504 fails intermittently because Example_gracefulShutdown prints an unexpected scheduler error. When shutdown interrupts a pgx query write, the driver can return write failed: ... i/o timeout instead of an error wrapping context.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.

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.
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
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't this generally always take precedent before we hit the context.Canceled check below?

@brandur
brandur merged commit 516a98e into master Oct 15, 2026
23 checks passed
@brandur
brandur deleted the bg/fix-graceful-shutdown-example branch October 15, 2026 04:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants