Skip to content

Commit 5070c14

Browse files
committed
netconn.go: Cleanup contexts on close
Updates #255
1 parent 642a013 commit 5070c14

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

netconn.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,8 @@ func NetConn(ctx context.Context, c *Conn, msgType MessageType) net.Conn {
5050
writeMu: newMu(c),
5151
}
5252

53-
var writeCancel context.CancelFunc
54-
nc.writeCtx, writeCancel = context.WithCancel(ctx)
55-
var readCancel context.CancelFunc
56-
nc.readCtx, readCancel = context.WithCancel(ctx)
53+
nc.writeCtx, nc.writeCancel = context.WithCancel(ctx)
54+
nc.readCtx, nc.readCancel = context.WithCancel(ctx)
5755

5856
nc.writeTimer = time.AfterFunc(math.MaxInt64, func() {
5957
if !nc.writeMu.tryLock() {
@@ -98,11 +96,13 @@ type netConn struct {
9896
writeMu *mu
9997
writeExpired int64
10098
writeCtx context.Context
99+
writeCancel context.CancelFunc
101100

102101
readTimer *time.Timer
103102
readMu *mu
104103
readExpired int64
105104
readCtx context.Context
105+
readCancel context.CancelFunc
106106
readEOFed bool
107107
reader io.Reader
108108
}
@@ -111,7 +111,9 @@ var _ net.Conn = &netConn{}
111111

112112
func (nc *netConn) Close() error {
113113
nc.writeTimer.Stop()
114+
nc.writeCancel()
114115
nc.readTimer.Stop()
116+
nc.readCancel()
115117
return nc.c.Close(StatusNormalClosure, "")
116118
}
117119

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy