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 {
4848 setConnContext chan context.Context
4949 getConnContext chan context.Context
5050
51- pingListener map [string ]chan <- struct {}
51+ pingListenerMu sync.Mutex
52+ pingListener map [string ]chan <- struct {}
5253}
5354
5455// Context returns a context derived from parent that will be cancelled
@@ -254,7 +255,9 @@ func (c *Conn) handleControl(h header) {
254255 case opPing :
255256 c .writePong (b )
256257 case opPong :
258+ c .pingListenerMu .Lock ()
257259 listener , ok := c .pingListener [string (b )]
260+ c .pingListenerMu .Unlock ()
258261 if ok {
259262 close (listener )
260263 }
@@ -717,7 +720,16 @@ func (c *Conn) ping(ctx context.Context) error {
717720 p := strconv .FormatUint (id , 10 )
718721
719722 pong := make (chan struct {})
723+
724+ c .pingListenerMu .Lock ()
720725 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+ }()
721733
722734 err := c .writeMessage (ctx , opPing , []byte (p ))
723735 if err != nil {
You can’t perform that action at this time.
0 commit comments