From 66aec4478f0a0945072a6823b5657dc6793548c6 Mon Sep 17 00:00:00 2001 From: talksik Date: Thu, 9 Apr 2026 16:18:38 -0700 Subject: [PATCH] fix: websocket connections unreliable Constant disconnection and reconnection every couple minutes or less. --- go/internal/pusher/conn.go | 3 ++- go/k8s/dev/pusher.yaml | 18 ++++++++++++++++++ go/k8s/prod/pusher.yaml | 18 ++++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/go/internal/pusher/conn.go b/go/internal/pusher/conn.go index c28ab33..89d46c7 100644 --- a/go/internal/pusher/conn.go +++ b/go/internal/pusher/conn.go @@ -38,9 +38,10 @@ func (c *Conn) ReadPump(ctx context.Context, hub *Hub) { _, data, err := c.ws.Read(ctx) if err != nil { if ctx.Err() != nil { + slog.Info("websocket context cancelled", "connId", c.id, "humanId", c.humanID, "error", ctx.Err()) return } - slog.Debug("websocket read error", "connId", c.id, "error", err) + slog.Info("websocket read error", "connId", c.id, "humanId", c.humanID, "error", err) return } diff --git a/go/k8s/dev/pusher.yaml b/go/k8s/dev/pusher.yaml index 3053761..8548375 100644 --- a/go/k8s/dev/pusher.yaml +++ b/go/k8s/dev/pusher.yaml @@ -80,6 +80,24 @@ spec: --- +# WebSocket connections need a much longer timeout than the default 30s. +# Without this, GKE terminates idle WS connections after 30 seconds. +apiVersion: networking.gke.io/v1 +kind: GCPBackendPolicy +metadata: + name: pusher-backend-policy +spec: + default: + timeoutSec: 60 + connectionDraining: + drainingTimeoutSec: 30 + targetRef: + group: "" + kind: Service + name: pusher + +--- + apiVersion: networking.gke.io/v1 kind: HealthCheckPolicy metadata: diff --git a/go/k8s/prod/pusher.yaml b/go/k8s/prod/pusher.yaml index 2eed66b..e4649a5 100644 --- a/go/k8s/prod/pusher.yaml +++ b/go/k8s/prod/pusher.yaml @@ -77,6 +77,24 @@ spec: --- +# WebSocket connections need a much longer timeout than the default 30s. +# Without this, GKE terminates idle WS connections after 30 seconds. +apiVersion: networking.gke.io/v1 +kind: GCPBackendPolicy +metadata: + name: pusher-backend-policy +spec: + default: + timeoutSec: 60 + connectionDraining: + drainingTimeoutSec: 30 + targetRef: + group: "" + kind: Service + name: pusher + +--- + apiVersion: networking.gke.io/v1 kind: HealthCheckPolicy metadata: