Skip to content

Commit 0d7b91a

Browse files
authored
Fixed SetReadDeadline before connCheck (#1299)
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
1 parent 6cf3092 commit 0d7b91a

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

packets.go

+7-8
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,13 @@ 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+
if mc.cfg.ReadTimeout != 0 {
115+
err = conn.SetReadDeadline(time.Now().Add(mc.cfg.ReadTimeout))
116+
}
117+
if err == nil {
118+
err = connCheck(conn)
119+
}
121120
}
122121
if err != nil {
123122
errLog.Print("closing bad idle connection: ", err)

0 commit comments

Comments
 (0)