neondatabase / neondatabase/serverless
Uncaught Exception When Terminating Query by PID – server conn crashed? Error
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 548
- Forks
- 81
- PR merge metrics
- No merged PRs in 30d
Description
Hi Neon team,
We are currently implementing a service that allows the frontend to cancel long-running queries by calling an API endpoint that terminates the query using its PostgreSQL PID (via pg_terminate_backend). However, we consistently encounter an uncaught exception from the Neon client when this happens.
❗ Problem
Whenever the query is forcefully terminated using pg_terminate_backend, we receive the following error from the Neon client library:
Uncaught Exception: error: server conn crashed? at bn.parseErrorMessage (C:\Users\xxx\Documents\GitHub\project\node_modules\@neondatabase\serverless\index.js:949:41) at bn.handlePacket (C:\Users\xxx\Documents\GitHub\project\node_modules\@neondatabase\serverless\index.js:917:75) at bn.parse (C:\Users\xxx\Documents\GitHub\project\node_modules\@neondatabase\serverless\index.js:905:36) at S.<anonymous> (C:\Users\xxx\Documents\GitHub\project\node_modules\@neondatabase\serverless\index.js:956:16) at S.emit (C:\Users\xxx\Documents\GitHub\project\node_modules\@neondatabase\serverless\index.js:316:79) at WebSocket.<anonymous> (C:\Users\xxx\Documents\GitHub\project\node_modules\@neondatabase\serverless\index.js:398:19)
Context :
We are using the @neondatabase/serverless package to connect to our Neon PostgreSQL database.
When the frontend decides that a query is no longer needed (e.g. the user navigates away), it sends a request to our backend to terminate the running query.
The backend issues a SELECT pg_terminate_backend() against the database.
Immediately after that, the Neon client throws an uncaught error and crashes the Node.js process.
🛠️ Expected Behavior
We expect the client to gracefully handle the server-side termination of a query (via pg_terminate_backend) and return a structured error, rather than crashing the process.
✅ Reproduction Steps
Start a long-running query via a Node.js backend using @neondatabase/serverless.
From another request (e.g. triggered by the frontend), call pg_terminate_backend() on that query.
Observe the uncaught exception and stack trace in the Node.js server logs.
📦 Environment
@neondatabase/serverless version: 1.0.0
Node.js version: 24.0.0
Platform: Windows 11
Neon DB: Serverless
🙏 Request
It would be great if the Neon client could catch and properly handle this error scenario, ideally exposing a clear error message that the query was terminated, instead of throwing an uncaught exception.
Thanks in advance!
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the long-running query cancellation using @neondatabase/serverless and SELECT pg_terminate_backend(), then inspect the failure path reported in node_modules/@neondatabase/serverless/index.js. Verify how the client handles the terminated connection and confirm that the process no longer receives an uncaught exception and exposes a structured termination error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js, postgresql
- Domain
- backend, databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100