Skip to content

Commit 93f1a64

Browse files
committed
fix Data race between mysqlConn.cleanup() and writeHandshakeResponsePacket
close #1567
1 parent 00727fe commit 93f1a64

File tree

3 files changed

+2
-7
lines changed

3 files changed

+2
-7
lines changed

connection.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,7 @@ func (mc *mysqlConn) cleanup() {
153153

154154
// Makes cleanup idempotent
155155
close(mc.closech)
156-
nc := mc.netConn
157-
if nc == nil {
158-
return
159-
}
160-
if err := nc.Close(); err != nil {
156+
if err := mc.rawConn.Close(); err != nil {
161157
mc.log(err)
162158
}
163159
// This function can be called from multiple goroutines.

connector.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,10 @@ func (c *connector) Connect(ctx context.Context) (driver.Conn, error) {
102102
nd := net.Dialer{Timeout: mc.cfg.Timeout}
103103
mc.netConn, err = nd.DialContext(ctx, mc.cfg.Net, mc.cfg.Addr)
104104
}
105-
106105
if err != nil {
107106
return nil, err
108107
}
108+
mc.rawConn = mc.netConn
109109

110110
// Enable TCP Keepalives on TCP connections
111111
if tc, ok := mc.netConn.(*net.TCPConn); ok {

packets.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,6 @@ func (mc *mysqlConn) writeHandshakeResponsePacket(authResp []byte, plugin string
351351
if err := tlsConn.Handshake(); err != nil {
352352
return err
353353
}
354-
mc.rawConn = mc.netConn
355354
mc.netConn = tlsConn
356355
mc.buf.nc = tlsConn
357356
}

0 commit comments

Comments
 (0)