Skip to content

Commit dd78f9e

Browse files
author
Vijay Karthik
committed
Fix handling timeout errors
The comment in `database/sql/driver/driver.go` mentions ``` // To prevent duplicate operations, ErrBadConn should NOT be returned // if there's a possibility that the database server might have // performed the operation. Even if the server sends back an error, // you shouldn't return ErrBadConn. var ErrBadConn = errors.New("driver: bad connection") ``` Network error could be a timeout error where the database might have executed the query. This commit adds a check so that ErrBadConn is not returned for timeout errors Fixes #422
1 parent 88edab0 commit dd78f9e

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

error.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,12 @@ func (c *conn) errRecover(err *error) {
488488
*err = v
489489
}
490490
case *net.OpError:
491-
*err = driver.ErrBadConn
491+
if v.Timeout() {
492+
c.bad = true
493+
*err = v
494+
} else {
495+
*err = driver.ErrBadConn
496+
}
492497
case error:
493498
if v == io.EOF || v.(error).Error() == "remote error: handshake failure" {
494499
*err = driver.ErrBadConn

0 commit comments

Comments
 (0)