Skip to content

Conversation

@rchandranmani
Copy link
Contributor

@rchandranmani rchandranmani commented Jun 26, 2025

Our application was crashing when the database connection unexpectedly failed. This happened because:

  1. We were previously using removeAllListeners('error'), which unintentionally removed the pg library's error handlers.
  2. This left connection termination errors unhandled, leading to app crashes which uses this connector

We've fixed this by:

  1. Completely removing the removeAllListeners('error') call within the connector. This ensures that the pg library's built-in error handling for connection issues remains active.
  2. We now only add our connector's specific error listener if the pg client doesn't already have any error listeners attached (!pg.listenerCount('error')). This prevents us from creating too many listeners (addressing past MaxEventListeners warnings) while ensuring all critical connection errors are still properly managed.

Fixes #778
See also #746

Checklist

  • DCO (Developer Certificate of Origin) signed in all commits
  • npm test passes on your machine
  • New tests added or existing tests modified to cover all changes
  • Code conforms with the style guide
  • Commit messages are following our guidelines
renovate bot and others added 3 commits June 27, 2025 11:44
Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Signed-off-by: Ramachandran Mani <m.chandru.m@gmail.com>
Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Signed-off-by: Ramachandran Mani <m.chandru.m@gmail.com>
Signed-off-by: Ramachandran Mani <m.chandru.m@gmail.com>
@rchandranmani rchandranmani deleted the fix-listener-error branch June 27, 2025 19:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant