Skip to content

Return the cancel request's promise from query.cancel() - #1237

Open
chrbala wants to merge 1 commit into
porsager:masterfrom
chrbala:fix-cancel-returns-promise
Open

chrbala wants to merge 1 commit into
porsager:masterfrom
chrbala:fix-cancel-returns-promise

Conversation

@chrbala

@chrbala chrbala commented Sep 30, 2026

Copy link
Copy Markdown

query.cancel() sent the cancel request on a connection of its own but dropped the promise that request settles, and returned null. A cancel request that failed, for example because that connection could not be opened, was then an unhandled rejection, which ends a Node process by default, and the caller had no way to handle it.

Return the promise instead, and the same promise on later calls, which still send no second request. Its type is now Promise<void>, and the README says how it settles.

`query.cancel()` sent the cancel request on a connection of its own but
dropped the promise that request settles, and returned null. A cancel
request that failed, for example because that connection could not be
opened, was then an unhandled rejection, which ends a Node process by
default, and the caller had no way to handle it.

Return the promise instead, and the same promise on later calls, which
still send no second request. Its type is now `Promise<void>`, and the
README says how it settles.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@chrbala

chrbala commented Sep 30, 2026

Copy link
Copy Markdown
Author

I made a few PRs from Claude which fix some problems I was having. Can you take a look?

colll78 added a commit to Anastasia-Labs/midgard that referenced this pull request Oct 6, 2026
@effect/sql-pg cancels every running query it interrupts, and postgres.js
sends that cancel on a connection of its own, then settles a promise that
Query.cancel() drops. When that connection is refused or reset (Postgres
restarting or unreachable at that moment), the rejection is unhandled, and
a node with no handler for one exits.

Extend the postgres 3.4.9 patch, ESM and CommonJS: cancel() sends the
request once, handles a rejection of its promise itself and returns the
promise, as the open upstream pull request porsager/postgres#1237 does
without the handler. postgres.js has no hook to report the failure to;
a failed cancel leaves the query running to its end, and the query's own
result and failure path are unchanged. No released postgres version
fixes this (3.4.9 is the latest).

A real-Postgres test resets the cancel connection behind a proxy and
checks there is no unhandled rejection and the pool serves the next
query.
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.

1 participant