From e3d431d0dfa929b048406254be2b1390437e716a Mon Sep 17 00:00:00 2001 From: Jack Christensen Date: Sat, 26 Jan 2019 16:45:06 -0600 Subject: [PATCH] writeAll dies on permanent net errors --- pgconn/pgconn.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pgconn/pgconn.go b/pgconn/pgconn.go index 461ff1c0..06f9e833 100644 --- a/pgconn/pgconn.go +++ b/pgconn/pgconn.go @@ -398,11 +398,15 @@ func (pgConn *PgConn) hardClose() error { return pgConn.conn.Close() } -// writeAll writes the entire buffer successfully or it hard closes the connection. +// writeAll writes the entire buffer. The connection is hard closed on a partial write or a non-temporary error. func (pgConn *PgConn) writeAll(buf []byte) error { n, err := pgConn.conn.Write(buf) - if err != nil && n > 0 { - pgConn.hardClose() + if err != nil { + if n > 0 { + pgConn.hardClose() + } else if ne, ok := err.(net.Error); ok && !ne.Temporary() { + pgConn.hardClose() + } } return err }