2
0

pgconn.CheckConn locks connection

This ensures that a closed connection at the pgconn layer is not
considered okay when the background closing of the net.Conn is still in
progress.

This also means that CheckConn cannot be called when the connection is
locked (for example, by in an progress query). But that seems
reasonable. It's not exactly clear that that would have ever worked
anyway.

https://github.com/jackc/pgx/issues/1618#issuecomment-1563702231
This commit is contained in:
Jack Christensen
2023-05-26 06:03:25 -05:00
parent 70a200cff4
commit b3739c1289
+5
View File
@@ -1644,6 +1644,11 @@ func (pgConn *PgConn) EscapeString(s string) (string, error) {
// connection. If this is done immediately before sending a query it reduces the chances a query will be sent that fails
// without the client knowing whether the server received it or not.
func (pgConn *PgConn) CheckConn() error {
if err := pgConn.lock(); err != nil {
return err
}
defer pgConn.unlock()
err := pgConn.conn.BufferReadUntilBlock()
if err != nil && !errors.Is(err, nbconn.ErrWouldBlock) {
return err