Skip to content

Commit

Permalink
Fixed SetReadDeadline before connCheck (go-sql-driver#1299)
Browse files Browse the repository at this point in the history
there's no need to set conn's readline if CheckConnLiveness is false,
and the ReadTimeout shall work with rawConn.Read inside conncheck.
buffer.fill will do SetReadDeadline if needed
  • Loading branch information
zjj committed Jan 10, 2022
1 parent 6cf3092 commit 0d7b91a
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions packets.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,13 @@ func (mc *mysqlConn) writePacket(data []byte) error {
conn = mc.rawConn
}
var err error
// If this connection has a ReadTimeout which we've been setting on
// reads, reset it to its default value before we attempt a non-blocking
// read, otherwise the scheduler will just time us out before we can read
if mc.cfg.ReadTimeout != 0 {
err = conn.SetReadDeadline(time.Time{})
}
if err == nil && mc.cfg.CheckConnLiveness {
err = connCheck(conn)
if mc.cfg.CheckConnLiveness {
if mc.cfg.ReadTimeout != 0 {
err = conn.SetReadDeadline(time.Now().Add(mc.cfg.ReadTimeout))
}
if err == nil {
err = connCheck(conn)
}
}
if err != nil {
errLog.Print("closing bad idle connection: ", err)
Expand Down

0 comments on commit 0d7b91a

Please sign in to comment.