@@ -50,16 +50,14 @@ func NetConn(ctx context.Context, c *Conn, msgType MessageType) net.Conn {
50
50
writeMu : newMu (c ),
51
51
}
52
52
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 )
57
55
58
56
nc .writeTimer = time .AfterFunc (math .MaxInt64 , func () {
59
57
if ! nc .writeMu .tryLock () {
60
58
// If the lock cannot be acquired, then there is an
61
59
// active write goroutine and so we should cancel the context.
62
- writeCancel ()
60
+ nc . writeCancel ()
63
61
return
64
62
}
65
63
defer nc .writeMu .unlock ()
@@ -75,7 +73,7 @@ func NetConn(ctx context.Context, c *Conn, msgType MessageType) net.Conn {
75
73
if ! nc .readMu .tryLock () {
76
74
// If the lock cannot be acquired, then there is an
77
75
// active read goroutine and so we should cancel the context.
78
- readCancel ()
76
+ nc . readCancel ()
79
77
return
80
78
}
81
79
defer nc .readMu .unlock ()
@@ -98,11 +96,13 @@ type netConn struct {
98
96
writeMu * mu
99
97
writeExpired int64
100
98
writeCtx context.Context
99
+ writeCancel context.CancelFunc
101
100
102
101
readTimer * time.Timer
103
102
readMu * mu
104
103
readExpired int64
105
104
readCtx context.Context
105
+ readCancel context.CancelFunc
106
106
readEOFed bool
107
107
reader io.Reader
108
108
}
@@ -111,7 +111,9 @@ var _ net.Conn = &netConn{}
111
111
112
112
func (nc * netConn ) Close () error {
113
113
nc .writeTimer .Stop ()
114
+ nc .writeCancel ()
114
115
nc .readTimer .Stop ()
116
+ nc .readCancel ()
115
117
return nc .c .Close (StatusNormalClosure , "" )
116
118
}
117
119
0 commit comments