Skip to content

Cancelling a query you don't await crashes the process with an unhandled rejection #130

Closed

Description

@okomarov

A cancelled query's own promise rejects (with 57014, or the server's error when the cancel arrives too late). Code that cancels a query and moves on without awaiting it gets an unhandled rejection, which ends a Node process by default:

const q = sql`select pg_sleep(10)`.execute()
await q.cancel()
// q is never awaited
UNHANDLED REJECTION: 57014 57014: canceling statement due to user request

Reproduced against the fork with a queued query (a server that accepts the connection and never answers). The code is unchanged from 3.4.9. Today every cancel needs a q.catch(() => {}) next to it.

Fix: query.cancel() marks the query's rejection as handled. Code that awaits the query still receives the error; code that cancels and moves on no longer crashes. Upstream has nothing reporting this; the nearest are the cancel request's own promise (upstream PR 1237, already handled here) and the internal type query being cancelled (upstream 1205).

Activity

  1. added this to the 4.5.0 milestone on Oct 17, 2026
  2. added
    bug
    area: protocol
    on Oct 17, 2026
  3. moved this to In progress in Roadmapon Oct 17, 2026
  4. added a commit that references this issue on Oct 17, 2026
  5. okomarov commented on Oct 17, 2026

    @okomarov
    Author

    Shipped in 4.5.0.

  6. moved this from In progress to Shipped in Roadmapon Oct 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: protocolbug

    Type

    No type

    Projects

    • Status
      Shipped

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions