From eb81d2926b3b0519cd1fe945c2795cceeabe236c Mon Sep 17 00:00:00 2001 From: Jack Christensen Date: Mon, 18 Nov 2019 07:24:05 -0600 Subject: [PATCH] Ignore errors sending Terminate message while closing connection This mimics the behavior of libpq PGfinish. refs #637 --- pgconn.go | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/pgconn.go b/pgconn.go index e3f3aaff..210d9979 100644 --- a/pgconn.go +++ b/pgconn.go @@ -492,15 +492,13 @@ func (pgConn *PgConn) Close(ctx context.Context) error { pgConn.contextWatcher.Watch(ctx) defer pgConn.contextWatcher.Unwatch() - _, err := pgConn.conn.Write([]byte{'X', 0, 0, 0, 4}) - if err != nil { - return err - } - - _, err = pgConn.conn.Read(make([]byte, 1)) - if err != io.EOF { - return err - } + // Ignore any errors sending Terminate message and waiting for server to close connection. + // This mimics the behavior of libpq PQfinish. It calls closePGconn which calls sendTerminateConn which purposefully + // ignores errors. + // + // See https://github.com/jackc/pgx/issues/637 + pgConn.conn.Write([]byte{'X', 0, 0, 0, 4}) + pgConn.conn.Read(make([]byte, 1)) return pgConn.conn.Close() }