File tree Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -48,7 +48,8 @@ type Conn struct {
48
48
setConnContext chan context.Context
49
49
getConnContext chan context.Context
50
50
51
- pingListener map [string ]chan <- struct {}
51
+ pingListenerMu sync.Mutex
52
+ pingListener map [string ]chan <- struct {}
52
53
}
53
54
54
55
// Context returns a context derived from parent that will be cancelled
@@ -254,7 +255,9 @@ func (c *Conn) handleControl(h header) {
254
255
case opPing :
255
256
c .writePong (b )
256
257
case opPong :
258
+ c .pingListenerMu .Lock ()
257
259
listener , ok := c .pingListener [string (b )]
260
+ c .pingListenerMu .Unlock ()
258
261
if ok {
259
262
close (listener )
260
263
}
@@ -717,7 +720,16 @@ func (c *Conn) ping(ctx context.Context) error {
717
720
p := strconv .FormatUint (id , 10 )
718
721
719
722
pong := make (chan struct {})
723
+
724
+ c .pingListenerMu .Lock ()
720
725
c .pingListener [p ] = pong
726
+ c .pingListenerMu .Unlock ()
727
+
728
+ defer func () {
729
+ c .pingListenerMu .Lock ()
730
+ delete (c .pingListener , p )
731
+ c .pingListenerMu .Unlock ()
732
+ }()
721
733
722
734
err := c .writeMessage (ctx , opPing , []byte (p ))
723
735
if err != nil {
You can’t perform that action at this time.
0 commit comments