Skip to content

[SHIPPED in 4.5.0] await using on the pool and reserved connections #52

Closed

Description

@okomarov

Explicit resource management would make forgetting sql.end() or reserved.release() impossible to write:

await using sql = postgres()         // sql.end() at the end of the scope
using reserved = await sql.reserve() // reserved.release() at the end of the scope

Requested upstream in porsager#886 and porsager#1094.

Proposal

  • The pool gets [Symbol.asyncDispose], which calls end(). Only the top-level instance: transaction and reserved handles must never end the pool.
  • Reserved connections get [Symbol.dispose] and [Symbol.asyncDispose], both calling release().
  • Transaction, savepoint and cursor handles are already scoped by their callbacks or for await, so they stay as they are.
  • Types for both, and README examples under "Teardown / Cleanup" and reserved.release().

The using syntax needs Node.js 24+ or TypeScript 5.2+; the symbols exist on Node 22, so the methods can be called directly there.

Activity

  1. added a commit that references this issue on Oct 15, 2026
  2. moved this to Shipped in Roadmapon Oct 15, 2026
  3. added
    area: transactions
    enhancement
    on Oct 16, 2026
  4. changed the title [-]Support await using on the pool and reserved connections[/-] [+][SHIPPED in 4.5.0] await using on the pool and reserved connections[/+] on 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: transactionsenhancement

    Type

    No type

    Projects

    • Status
      Shipped

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions