-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Description
There are two bugs in different parts of the library which, can lead to unpredictable behavior if value serialization fails.
- Serializer state is not cleaned up on error
In the serializer, writer and paramWriter may not be cleaned up if an exception is thrown in the writeValues function:
| writeValues(values, config.valueMapper) |
As a result, parameters from one query (which failed, but may was processed partially) can be sent to next query. I am not an expert in the PostgreSQL protocol, but it appears that reusing global writers in this way can theoretically lead to other unpredictable behavior as well.
When I made a local change to avoid reusing the writer, a second issue became apparent.
- Prepared statement is not properly closed on bind error
In the query prepare function, if an error occurs during the bind call (triggered by the first issue), the prepared statement is not properly closed:
node-postgres/packages/pg/lib/query.js
Line 231 in ecff60d
| this.handleError(err, connection) |
When using a pooled client, this causes the client to remain in an active state indefinitely, effectively leaking the connection.
I prepared PR to address those issues, but it would be nice to hear a feedback from active maintainers on this.