Fix racy usage of pgConn.contextWatcher in ayncClose
This commit is contained in:
@@ -518,13 +518,14 @@ func (pgConn *PgConn) ayncClose() {
|
|||||||
go func() {
|
go func() {
|
||||||
defer pgConn.conn.Close()
|
defer pgConn.conn.Close()
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*15)
|
deadline := time.Now().Add(time.Second * 15)
|
||||||
|
|
||||||
|
ctx, cancel := context.WithDeadline(context.Background(), deadline)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
pgConn.CancelRequest(ctx)
|
pgConn.CancelRequest(ctx)
|
||||||
|
|
||||||
pgConn.contextWatcher.Watch(ctx)
|
pgConn.conn.SetDeadline(deadline)
|
||||||
defer pgConn.contextWatcher.Unwatch()
|
|
||||||
|
|
||||||
pgConn.conn.Write([]byte{'X', 0, 0, 0, 4})
|
pgConn.conn.Write([]byte{'X', 0, 0, 0, 4})
|
||||||
pgConn.conn.Read(make([]byte, 1))
|
pgConn.conn.Read(make([]byte, 1))
|
||||||
|
|||||||
Reference in New Issue
Block a user