Skip to content

fix: add default error listeners - #3748

Closed
zfaustk wants to merge 1 commit into
brianc:masterfrom
zfaustk:fix/default-error-listeners
Closed

fix: add default error listeners#3748
zfaustk wants to merge 1 commit into
brianc:masterfrom
zfaustk:fix/default-error-listeners

Conversation

@zfaustk

@zfaustk zfaustk commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Summary

  • add a default no-op error listener to every Client, native-backed Client, and Pool
  • keep normal EventEmitter semantics for user listeners, including the original Error object
  • update pool guidance for the new pg@9 default

Fixes #3630.

Why

Today an otherwise-unobserved background error event throws through Node's EventEmitter and can terminate the process. The operation-specific errors have already been returned, so pg@9 can provide a safer default while applications that add an error listener continue to observe and handle the same event.

This intentionally changes the behavior of unobserved error events and is scoped to the pg@9.0 milestone.

Testing

  • packages/pg/test/unit/client/configuration-tests.js (13 checks passed)
  • focused packages/pg-pool/test/events.js error-listener cases (2 passed)
  • public runtime RED-to-GREEN for Pool; actual JavaScript and native-backed Client constructors verified with the same Error reaching a user listener
  • ESLint on all changed JavaScript files
  • Prettier 3.0.3 on all changed files
  • node --check on all changed JavaScript files and git diff --check

The full yarn test matrix was not run locally. The remaining database-backed tests in packages/pg-pool/test/events.js require a PostgreSQL service and stopped with ECONNREFUSED in this environment; upstream CI covers the Node/PostgreSQL matrix and native libpq suite.

Authorship

Implemented and tested with Codex assistance. No human-review claim is made.

## Context
- Principle: Client and Pool background errors should reach explicit observers without becoming uncaught exceptions by default.
- Why: Unobserved EventEmitter error events can terminate the process even after operation-level errors have already been returned.

## Key Deltas
- Error emitters: Client, native Client, and Pool had no default handler -> each instance absorbs only otherwise-unobserved error events; why: preserve process stability while retaining normal user listeners. Key refs: packages/pg/lib/client.js:53, packages/pg/lib/native/client.js:25, packages/pg-pool/index.js:69
- Regression coverage: error behavior was implicit -> public emit behavior covers both no-listener and user-listener cases; why: prove the same Error still reaches user code. Key refs: packages/pg/test/unit/client/configuration-tests.js:13, packages/pg/test/native/evented-api-tests.js:9, packages/pg-pool/test/events.js:10
- Pool guidance: documentation warned of an uncaught exception -> guidance explains the default listener and recommends explicit observation; why: align the documented contract with pg@9 behavior. Key refs: docs/pages/apis/pool.mdx:264, packages/pg-pool/README.md:242

## Verification
Result: passed
@charmander

Copy link
Copy Markdown
Collaborator

bad tests, wrong target branch. i’ll just do it when the time comes

@charmander charmander closed this Aug 13, 2026
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.

## add default no-op error listener to pool and client

2 participants