Skip to content

Conversation

@KR-bluejay
Copy link
Contributor

@KR-bluejay KR-bluejay commented Oct 1, 2025

Related Issue

Description

  • Ensure active queries are cancelled during shutdown.
  • If the shutdown timeout elapses, PgDog now sends CANCEL requests to Postgres before tearing down connection pools, preventing long-running queries from lingering.

Code changes

  • frontend/listen.rs: Added query cancellation in execute_shutdown when shutdown timeout expires.

Testing

  • Added the new cancel_query scenario to integration/complex/run.sh and ran the script to verify shutdown cancellation

@CLAassistant
Copy link

CLAassistant commented Oct 1, 2025

CLA assistant check
All committers have signed the CLA.

);

// Shutdown timeout elapsed; cancel any still-running queries before tearing pools down.
let cancel_futures = comms.clients().into_keys().map(|id| async move {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is good. One note: let's make this code run conditionally on shutdown_termination_timeout being configured. Otherwise, this is good to go.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had read #517 as “cancel queries by default on shutdown, and use shutdown_termination_timeout only for how long we wait.”

If we guard the cancellation logic behind that option, we’d fall back to not cancelling at all.

Was the intent to keep cancellation optional, or should we still do it by default and let the timeout act purely as a safeguard?

Copy link
Collaborator

Choose a reason for hiding this comment

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

If we guard the cancellation logic behind that option, we’d fall back to not cancelling at all.

That's right, we want this feature to be optional. If we allow query cancellation without a timeout, it can block pgdog from shutting down if the network is unreliable.

The timeout is a safeguard, and we can't use this feature without it safely.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for clarifying!

I'll modify the code to only run cancellation when the timeout is set

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. The cancellation now only runs when shutdown_termination_timeout is configured (updated in the latest commit).

Heads-up: once this lands, I’ll open an issue in the docs repo and follow up with the config update there.

@KR-bluejay KR-bluejay marked this pull request as ready for review October 8, 2025 04:19
Copy link
Collaborator

@levkk levkk left a comment

Choose a reason for hiding this comment

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

Great! Thank you!

@levkk levkk merged commit 46e7142 into pgdogdev:main Oct 8, 2025
1 check passed
@KR-bluejay KR-bluejay deleted the fix/cancel-on-shutdown branch October 8, 2025 09:01
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.

Cancel queries on shutdown

3 participants