Skip to content

Prevent stuck cancellation from blocking connection teardown - #1370

Merged
elprans merged 1 commit into
masterfrom
cancellation-timeout
Sep 23, 2026
Merged

elprans merged 1 commit into
masterfrom
cancellation-timeout

Conversation

@elprans

@elprans elprans commented Sep 23, 2026

Copy link
Copy Markdown
Member

Use connection command timeout budget when waiting for cancellation and
abort the connection if cancellation cannot finish in time.

Fixes: #1326
Closes: #1349

Copilot AI lite review requested due to automatic review settings September 23, 2026 17:46

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot review overview

🟢 Approval recommended

No unresolved blocking issues were identified.

Review effort: Lite
Findings: None

What changed in this PR

Prevents stalled PostgreSQL cancellation requests from blocking connection and pool teardown.

Changes:

  • Applies timeout budgets to cancellation waits.
  • Aborts connections when cancellation exceeds its deadline.
  • Adds regression tests for connection, pool, and network-loss scenarios.
File Summary
tests/​test_timeout.py Tests cancellation and close timeouts.
tests/​test_pool.py Tests pool release during cancellation.
tests/​test_adversity.py Tests cancellation during network loss.
asyncpg/​protocol/​protocol.pyx Adds timeout-aware cancellation and teardown.
asyncpg/​protocol/​protocol.pyi Updates cancellation method typing.
asyncpg/​pool.py Propagates release timeout budgets.
asyncpg/​connection.py Tracks and cleans up cancellation tasks.
asyncpg/​connect_utils.py Safely cleans up cancellation transports.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Use connection command timeout budget when waiting for cancellation and
abort the connection if cancellation cannot finish in time.

Fixes: #1326
Closes: #1349
@elprans
elprans force-pushed the cancellation-timeout branch from 0cf4c21 to 526444b Compare September 23, 2026 18:20
@elprans
elprans merged commit 4cf0220 into master Sep 23, 2026
53 checks passed
@elprans
elprans deleted the cancellation-timeout branch September 23, 2026 19:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants