Skip to content

Commit 1c17177

Browse files
committed
Only call destroy on a client when it is not already being destroyed
Adds a check in the error listener on the client in the pool, to prevent calling destroy on a client when it is already being destroyed. Without this check, if an error occurs during the ending of the stream, such as a timeout, the client is never removed from the pool and weird things happen.
1 parent ac0d1c7 commit 1c17177

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

lib/pool.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,13 @@ var pools = {
3030
//via the pg object and then removing errored client from the pool
3131
client.on('error', function(e) {
3232
pool.emit('error', e, client);
33-
pool.destroy(client);
33+
34+
// If the client is already being destroyed, the error
35+
// occurred during stream ending. Do not attempt to destroy
36+
// the client again.
37+
if (!client._destroying) {
38+
pool.destroy(client);
39+
}
3440
});
3541

3642
// Remove connection from pool on disconnect

0 commit comments

Comments
 (0)