Skip to content

Commit d5f1053

Browse files
Lower the websocket ping interval from 30 to 2 seconds (#280)
This will allow us to detect disconnects much earlier. Ping packets are very light and don't use a lot of bandwidth.
1 parent aa58585 commit d5f1053

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

internal/signaling/handler.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func Handler(ctx context.Context, store stores.Store, cloudflare *cloudflare.Cre
7272
}
7373
defer func() {
7474
logger.Info("peer websocket closed", zap.String("peer", peer.ID), zap.String("game", peer.Game), zap.String("origin", r.Header.Get("Origin")))
75-
conn.Close(websocket.StatusInternalError, "unexpected closure")
75+
conn.Close(websocket.StatusInternalError, "unexpected closure") // nolint:errcheck
7676

7777
if !peer.closedPacketReceived {
7878
// At this point ctx has already been cancelled, so we create a new one to use for the disconnect.
@@ -82,8 +82,8 @@ func Handler(ctx context.Context, store stores.Store, cloudflare *cloudflare.Cre
8282
}
8383
}()
8484

85-
go func() { // Sending ping packet every 30 to check if the tcp connection is still alive.
86-
ticker := time.NewTicker(30 * time.Second)
85+
go func() { // Sending ping packet every 2 seconds to check if the tcp connection is still alive.
86+
ticker := time.NewTicker(2 * time.Second)
8787
defer ticker.Stop()
8888
for {
8989
select {

0 commit comments

Comments
 (0)