Skip to content

fix: close Hyperdrive client after query failures - #290

Draft
kaijakagi-sys wants to merge 4 commits into
outerbase:mainfrom
kaijakagi-sys:fix/hyperdrive-query-cleanup
Draft

fix: close Hyperdrive client after query failures#290
kaijakagi-sys wants to merge 4 commits into
outerbase:mainfrom
kaijakagi-sys:fix/hyperdrive-query-cleanup

Conversation

@kaijakagi-sys

@kaijakagi-sys kaijakagi-sys commented Sep 8, 2026

Copy link
Copy Markdown

Problem

A failed Hyperdrive query skips sql.end() in the base implementation. Moving cleanup into finally fixes that leak, but an awaited cleanup rejection can then hide the original query rejection.

Change

  • Always close the Hyperdrive client after query success or failure.
  • Preserve the original query rejection if cleanup also fails, including an undefined rejection reason.
  • Keep cleanup-only errors visible and preserve background cleanup through executionContext.waitUntil().
  • Add ten focused lifecycle regression tests with a mocked Postgres client.

Verification

Base: bb227352135051a0dd50190d67c3e82b03f8e485. Updated head: 958168e4086f5b1b0f0dbe75400193eb06c5c93a.

  • Original leak: two rejection-cleanup tests failed before the initial fix.
  • Dual-failure regression against previous draft head bec45944ec3464ec1e2364a143c213f659bf4ed7: 2 failed, 8 passed.
  • Updated vitest run src/operation.hyperdrive.test.ts src/operation.test.ts: 21 passed.
  • Full suite: 161 passed, 4 RLS failures. Previous draft head: 155 passed, the same 4 failures.
  • Typecheck: the same 11 diagnostics at both revisions, apart from shifted source locations.
  • Prettier and git diff --check pass.

These are local Node 22.23.2 / Vitest 2.1.8 tests; no live Hyperdrive deployment was tested. The repository CI uses Node 20, which was not tested locally.

Short demonstration

Recorded local regression results, not a deployment recording:

hyperdrive-regression.mp4

Scope

Related to #71. This is a narrow regression contribution, not completion of the repository-wide 75% coverage goal. #153 covers successful Hyperdrive cleanup; this change covers query-rejection cleanup and simultaneous failures. No reward has been agreed for this slice; keeping this draft pending scope/eligibility confirmation.

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