Skip to content

fix: clean up query error listeners - #1120

Open
hsusul wants to merge 1 commit into
supabase:masterfrom
hsusul:fix/pool-query-error-listener-cleanup
Open

fix: clean up query error listeners#1120
hsusul wants to merge 1 commit into
supabase:masterfrom
hsusul:fix/pool-query-error-listener-cleanup

Conversation

@hsusul

@hsusul hsusul commented Aug 27, 2026

Copy link
Copy Markdown

Fixes #1118

What kind of change does this PR introduce?

Bug fix

What is the current behavior?

Every query adds a one-shot error listener to the shared PostgreSQL pool. Successful queries and query-level rejections do not remove it, so completed queries accumulate stale listeners and eventually trigger MaxListenersExceededWarning.

What is the new behavior?

The query wrapper now settles through shared resolve and reject paths that clear any delayed connection-error timer and remove the exact temporary pool listener. Connection-level pool errors retain their existing next-tick arbitration and still propagate to the caller.

Tests

Added focused mocked-pool coverage for:

  • repeated successful queries leaving no residual listeners
  • query rejections cleaning up their listener
  • active connection-level errors still propagating

Local validation:

  • npx vitest run test/db.test.ts — 3 passed
  • npm run check — passed
  • npm run build — passed
  • Prettier check — passed
  • git diff --check — passed

Docker-backed integration tests were unavailable because the local Docker daemon is not running.

Additional context

#911 introduced connection-level error propagation but does not clean up listeners after ordinary completion. Open #782 is a broader client abstraction refactor and does not report this listener leak.

Signed-off-by: Henry Su <henrysu4707@gmail.com>
@hsusul
hsusul requested review from a team, avallete and soedirgo as code owners August 27, 2026 00:45
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.

Successful queries retain pool error listeners

1 participant