Skip to content

Commit 16c4701

Browse files
committed
Accept pings as activity
1 parent a7a9d35 commit 16c4701

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

websocket.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -275,10 +275,11 @@ func (c *wsConn) handleChanOut(ch reflect.Value, req interface{}) error {
275275

276276
// handleCtxAsync handles context lifetimes for client
277277
// TODO: this should be aware of events going through chanHandlers, and quit
278-
// when the related channel is closed.
279-
// This should also probably be a single goroutine,
280-
// Note that not doing this should be fine for now as long as we are using
281-
// contexts correctly (cancelling when async functions are no longer is use)
278+
//
279+
// when the related channel is closed.
280+
// This should also probably be a single goroutine,
281+
// Note that not doing this should be fine for now as long as we are using
282+
// contexts correctly (cancelling when async functions are no longer is use)
282283
func (c *wsConn) handleCtxAsync(actx context.Context, id interface{}) {
283284
<-actx.Done()
284285

@@ -486,6 +487,14 @@ func (c *wsConn) setupPings() func() {
486487
}
487488
return nil
488489
})
490+
c.conn.SetPingHandler(func(appData string) error {
491+
// treat pings as pongs - this lets us register server activity even if it's too busg to respond to our pings
492+
select {
493+
case c.pongs <- struct{}{}:
494+
default:
495+
}
496+
return nil
497+
})
489498

490499
stop := make(chan struct{})
491500

0 commit comments

Comments
 (0)