mirror of
https://github.com/jackc/pgx.git
synced 2025-05-31 11:42:24 +00:00
Ignore errors sending Terminate message while closing connection
This mimics the behavior of libpq PGfinish. refs #637
This commit is contained in:
parent
9449f4b081
commit
eb81d2926b
16
pgconn.go
16
pgconn.go
@ -492,15 +492,13 @@ func (pgConn *PgConn) Close(ctx context.Context) error {
|
|||||||
pgConn.contextWatcher.Watch(ctx)
|
pgConn.contextWatcher.Watch(ctx)
|
||||||
defer pgConn.contextWatcher.Unwatch()
|
defer pgConn.contextWatcher.Unwatch()
|
||||||
|
|
||||||
_, err := pgConn.conn.Write([]byte{'X', 0, 0, 0, 4})
|
// Ignore any errors sending Terminate message and waiting for server to close connection.
|
||||||
if err != nil {
|
// This mimics the behavior of libpq PQfinish. It calls closePGconn which calls sendTerminateConn which purposefully
|
||||||
return err
|
// ignores errors.
|
||||||
}
|
//
|
||||||
|
// See https://github.com/jackc/pgx/issues/637
|
||||||
_, err = pgConn.conn.Read(make([]byte, 1))
|
pgConn.conn.Write([]byte{'X', 0, 0, 0, 4})
|
||||||
if err != io.EOF {
|
pgConn.conn.Read(make([]byte, 1))
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return pgConn.conn.Close()
|
return pgConn.conn.Close()
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user