DB Pool Leak Fix Part 2: req.destroyed vs req.socket.destroyed

08/04/2026

In this article, I wrote about a fix for db connection leaking.

In there I did something like this:

if (req.destroyed) {
  release();
  return;
}

Apparently req.destroyed is set to true not only when the connection is destroyed but also during normal request processing. According to the documentation, destroyed "is true after request.destroy() has been called". And that follows readable stream rules — when all data is read, the stream is automatically destroyed. The readable stream ends and req.destroyed becomes true while the socket is still alive. This means my check was a false positive on every request.

So, I had to look for something more reliable. I came to the finding that what I have to check is the request socket destroyed property.

if (req.socket.destroyed) {
  release();
  return;
}

req.socket.destroyed reflects the TCP connection state, not the readable stream lifecycle. It is only true when the client actually drops the connection.

Lab