Skip to content

Commit 9837d81

Browse files
committed
Fixed SetReadDeadline before connCheck
there's no need to set conn's readline if CheckConnLiveness is false, and the ReadTimeout shall works with rawConn.Read inside conncheck.
1 parent 6cf3092 commit 9837d81

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

packets.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,15 @@ func (mc *mysqlConn) writePacket(data []byte) error {
110110
conn = mc.rawConn
111111
}
112112
var err error
113-
// If this connection has a ReadTimeout which we've been setting on
114-
// reads, reset it to its default value before we attempt a non-blocking
115-
// read, otherwise the scheduler will just time us out before we can read
116-
if mc.cfg.ReadTimeout != 0 {
117-
err = conn.SetReadDeadline(time.Time{})
118-
}
119-
if err == nil && mc.cfg.CheckConnLiveness {
120-
err = connCheck(conn)
113+
if mc.cfg.CheckConnLiveness {
114+
readDeadline := time.Time{}
115+
if mc.cfg.ReadTimeout != 0 {
116+
readDeadline = time.Now().Add(mc.cfg.ReadTimeout)
117+
}
118+
err = conn.SetReadDeadline(readDeadline)
119+
if err == nil {
120+
err = connCheck(conn)
121+
}
121122
}
122123
if err != nil {
123124
errLog.Print("closing bad idle connection: ", err)

0 commit comments

Comments
 (0)