-
Notifications
You must be signed in to change notification settings - Fork 49
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!