@@ -50,16 +50,14 @@ func NetConn(ctx context.Context, c *Conn, msgType MessageType) net.Conn{
5050writeMu : 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
5856nc .writeTimer = time .AfterFunc (math .MaxInt64 , func (){
5957if ! nc .writeMu .tryLock (){
6058// If the lock cannot be acquired, then there is an
6159// active write goroutine and so we should cancel the context.
62- writeCancel ()
60+ nc . writeCancel ()
6361return
6462 }
6563defer nc .writeMu .unlock ()
@@ -75,7 +73,7 @@ func NetConn(ctx context.Context, c *Conn, msgType MessageType) net.Conn{
7573if ! nc .readMu .tryLock (){
7674// If the lock cannot be acquired, then there is an
7775// active read goroutine and so we should cancel the context.
78- readCancel ()
76+ nc . readCancel ()
7977return
8078 }
8179defer nc .readMu .unlock ()
@@ -98,11 +96,13 @@ type netConn struct{
9896writeMu * mu
9997writeExpired int64
10098writeCtx context.Context
99+ writeCancel context.CancelFunc
101100
102101readTimer * time.Timer
103102readMu * mu
104103readExpired int64
105104readCtx context.Context
105+ readCancel context.CancelFunc
106106readEOFed bool
107107reader io.Reader
108108}
@@ -111,7 +111,9 @@ var _ net.Conn = &netConn{}
111111
112112func (nc * netConn ) Close () error {
113113nc .writeTimer .Stop ()
114+ nc .writeCancel ()
114115nc .readTimer .Stop ()
116+ nc .readCancel ()
115117return nc .c .Close (StatusNormalClosure , "" )
116118}
117119
0 commit comments