P
Prisma6d ago
Masato

Server has closed the connection

Thank you for your continued support. I am having trouble with “server has closed the connection.” Prisma does not perform a connection health check after creating a connection, right? If the socket is closed due to TCP Idle Timeout in the network configuration or OS, rather than in the application or Prisma client, Prisma client will continue to hold the connection. As a result, an error “server has closed the connection” occurs when executing a query, and the query cannot be executed. Question - Is there a way to periodically check if the connection is available on the Prisma client side? Something like this (https://github.com/prisma/prisma/issues/13264#issuecomment-1633258460) - Is query retry processing necessary in this case? Like this (https://github.com/prisma/prisma/discussions/24490#discussioncomment-9743866) The actual flow is as follows.
sequenceDiagram
participant pc as Prisma Client
participant cr as Cloud Run
participant ds as DB Server

pc ->> cr: Execute connect()
cr ->> ds: Establish TCP connection
Note over pc,ds: Connection is established, but remains idle afterward

pc ->> pc: Idle state (for a long period)

Note over ds: DB server has no idle timeout
ds -->> ds: Periodically sends TCP Keepalive

ds ->> cr: TCP Keepalive check
cr -->> cr: ⚠️ No response (connection was already dropped due to idleness)

ds ->> cr: No Keepalive response → assumes disconnection
ds -->> ds: ⛔ Marks as "Connection reset by peer"
ds ->> cr: Closes the connection

pc ->> ds: Sends a delayed query (SELECT * FROM ..)
ds -->> pc: ⛔ Error response: "Server has closed the connection"
sequenceDiagram
participant pc as Prisma Client
participant cr as Cloud Run
participant ds as DB Server

pc ->> cr: Execute connect()
cr ->> ds: Establish TCP connection
Note over pc,ds: Connection is established, but remains idle afterward

pc ->> pc: Idle state (for a long period)

Note over ds: DB server has no idle timeout
ds -->> ds: Periodically sends TCP Keepalive

ds ->> cr: TCP Keepalive check
cr -->> cr: ⚠️ No response (connection was already dropped due to idleness)

ds ->> cr: No Keepalive response → assumes disconnection
ds -->> ds: ⛔ Marks as "Connection reset by peer"
ds ->> cr: Closes the connection

pc ->> ds: Sends a delayed query (SELECT * FROM ..)
ds -->> pc: ⛔ Error response: "Server has closed the connection"
Thank you.
GitHub
DB connection health check · Issue #13264 · prisma/prisma
Problem I need to check if the app is still connected to the DB. The solution must be universal for every database. Suggested solution Enable the "provider" field as a public (or getProvi...
GitHub
How am I supposed to retry P1017: Server has closed the connection ...
Question Possibly related to this issue, but I'm confused as to how applications are supposed to gracefully handle transient DB connection errors due to things like database/pgbouncer restarts....
4 Replies
Prisma AI Help
Salutations, traveler! I'm the Prisma AI Help Bot. You've reached a fork in the road: one path leads to the wisdom of the human sages (ETA: sometime today), and the other to my instantaneous insights. Which way shall we go?
Nurul
Nurul6d ago
GitHub
"server has closed the connection" and can not retry a query · pri...
Question Thank you for your continued support. I am having trouble with “server has closed the connection.” Prisma does not perform a connection health check after creating a connection, right? If ...
Masato
MasatoOP6d ago
Thank you for confirming my question and providing an answer! I always use Prisma and truly appreciate the work of the maintainers! I had another related question, so I posted it in the discussion thread.
Nurul
Nurul4d ago
Responded on the thread 👍

Did you find this page helpful?