Skip to content

fix(cli): fix flakes related to context cancellation when establishing pg connections #18246

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 5, 2025

Conversation

hugodutka
Copy link
Contributor

@hugodutka hugodutka commented Jun 5, 2025

Since #18195 was merged, we started running CLI tests with postgres instead of just dbmem. This surfaced errors related to context cancellation while establishing postgres connections.

This PR should fix coder/internal#672. Related to #15109.

@hugodutka hugodutka requested a review from johnstcn June 5, 2025 13:03
@hugodutka hugodutka changed the title fix(cli): flakes related to context cancellation while establishing pg connections fix(cli): fix flakes related to context cancellation when establishing pg connections Jun 5, 2025
Comment on lines 172 to 176
// When a test exits it cancels the context. If a transaction is open
// and a query is being executed, instead of a context.Canceled error
// we get a "driver: bad connection" error.
return
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't exiting with an open transaction be bugged behaviour? Could this mask someone forgetting to close a connection?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, I should probably make the comment clearer. It should be

When we cancel the context on a query that's being executed within a transaction, sometimes, instead of a context.Canceled error we get a "driver: bad connection" error.

I don't think this could mask someone forgetting to close a connection. I suppose it might mask someone closing a connection while a transaction is being executed? I'm not sure how the database would handle this scenario.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

seems to also be reported here: lib/pq#1137

@hugodutka hugodutka force-pushed the hugodutka/pg-cancellation-flakes branch from cf0daf4 to 3864e86 Compare June 5, 2025 13:36
@hugodutka hugodutka merged commit 623dcd9 into main Jun 5, 2025
36 checks passed
@hugodutka hugodutka deleted the hugodutka/pg-cancellation-flakes branch June 5, 2025 13:54
@github-actions github-actions bot locked and limited conversation to collaborators Jun 5, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

flake: TestServer/Logging fails with no rows returned for version select
2 participants