Skip to content

Commit

Permalink
Merge pull request #1013 from dhermes/handle-broken-pipe
Browse files Browse the repository at this point in the history
Mark `net.Conn` failed writes as recoverable when 0 bytes were written.
  • Loading branch information
maddyblue authored Nov 23, 2020
2 parents 083382b + 25eb21e commit fbd2a9a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
13 changes: 12 additions & 1 deletion conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -891,9 +891,20 @@ func (cn *conn) Exec(query string, args []driver.Value) (res driver.Result, err
return r, err
}

type safeRetryError struct {
Err error
}

func (se *safeRetryError) Error() string {
return se.Err.Error()
}

func (cn *conn) send(m *writeBuf) {
_, err := cn.c.Write(m.wrap())
n, err := cn.c.Write(m.wrap())
if err != nil {
if n == 0 {
err = &safeRetryError{Err: err}
}
panic(err)
}
}
Expand Down
3 changes: 3 additions & 0 deletions error.go
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,9 @@ func (cn *conn) errRecover(err *error) {
case *net.OpError:
cn.bad = true
*err = v
case *safeRetryError:
cn.bad = true
*err = driver.ErrBadConn
case error:
if v == io.EOF || v.(error).Error() == "remote error: handshake failure" {
*err = driver.ErrBadConn
Expand Down

0 comments on commit fbd2a9a

Please sign in to comment.