Skip to content

Commit 6b890cc

Browse files
committed
Ping reads its result; obeys the context's Done channel
1 parent 4a32ba5 commit 6b890cc

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

connection_go18.go

+14-1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,18 @@ import (
77
)
88

99
func (mc *mysqlConn) Ping(ctx context.Context) error {
10-
return mc.writeCommandPacket(comPing)
10+
err := mc.writeCommandPacket(comPing)
11+
if err != nil {
12+
return err
13+
}
14+
15+
select {
16+
case <-ctx.Done():
17+
mc.Close()
18+
return ctx.Err()
19+
default:
20+
}
21+
22+
_, err = mc.readResultOK()
23+
return err
1124
}

0 commit comments

Comments
 (0)