Skip to content

Commit

Permalink
Fix tcp broken pipe error
Browse files Browse the repository at this point in the history
Refer to upstream lib#1013
  • Loading branch information
yangru committed Aug 22, 2022
1 parent 3e9117c commit 1c6733d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
15 changes: 14 additions & 1 deletion conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -893,8 +893,21 @@ 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}
}
}
if err != nil {
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 (c *conn) errRecover(err *error) {
case *net.OpError:
c.bad = true
*err = v
case *safeRetryError:
c.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 1c6733d

Please sign in to comment.