increases timeout
This commit is contained in:
@@ -52,15 +52,15 @@ func main() {
|
|||||||
|
|
||||||
// Pusher core
|
// Pusher core
|
||||||
bridge := pusher.NewRedisBridge(pusherRedis, podID)
|
bridge := pusher.NewRedisBridge(pusherRedis, podID)
|
||||||
authorizer := pusher.NewAuthorizer(networkSvc)
|
|
||||||
hub := pusher.NewHub(bridge, authorizer)
|
|
||||||
bridge.SetHub(hub)
|
|
||||||
server := pusher.NewServer(hub, bridge, authSvc)
|
|
||||||
|
|
||||||
// Context for graceful shutdown
|
// Context for graceful shutdown
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
|
authorizer := pusher.NewAuthorizer(networkSvc)
|
||||||
|
hub := pusher.NewHub(bridge, authorizer)
|
||||||
|
bridge.SetHub(hub)
|
||||||
|
server := pusher.NewServer(ctx, hub, bridge, authSvc)
|
||||||
|
|
||||||
// Start hub event loop
|
// Start hub event loop
|
||||||
go hub.Run(ctx)
|
go hub.Run(ctx)
|
||||||
|
|
||||||
|
|||||||
@@ -15,14 +15,17 @@ import (
|
|||||||
type Server struct {
|
type Server struct {
|
||||||
pbpusher.UnimplementedPusherServiceServer
|
pbpusher.UnimplementedPusherServiceServer
|
||||||
|
|
||||||
|
ctx context.Context // server-scoped context for graceful shutdown
|
||||||
hub *Hub
|
hub *Hub
|
||||||
bridge *RedisBridge
|
bridge *RedisBridge
|
||||||
authSvc auth.AuthService
|
authSvc auth.AuthService
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewServer creates a new pusher server.
|
// NewServer creates a new pusher server. The ctx controls the lifetime of all
|
||||||
func NewServer(hub *Hub, bridge *RedisBridge, authSvc auth.AuthService) *Server {
|
// WebSocket connections — when cancelled, all connections are closed gracefully.
|
||||||
|
func NewServer(ctx context.Context, hub *Hub, bridge *RedisBridge, authSvc auth.AuthService) *Server {
|
||||||
return &Server{
|
return &Server{
|
||||||
|
ctx: ctx,
|
||||||
hub: hub,
|
hub: hub,
|
||||||
bridge: bridge,
|
bridge: bridge,
|
||||||
authSvc: authSvc,
|
authSvc: authSvc,
|
||||||
@@ -59,7 +62,10 @@ func (s *Server) HandleWebSocket(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
slog.Info("websocket connected", "connId", connID, "humanId", session.HumanId)
|
slog.Info("websocket connected", "connId", connID, "humanId", session.HumanId)
|
||||||
|
|
||||||
ctx, cancel := context.WithCancel(r.Context())
|
// Use server context, NOT r.Context(). After WebSocket upgrade, the HTTP
|
||||||
|
// request context can be cancelled by load balancers or Go's HTTP server,
|
||||||
|
// and nhooyr/websocket permanently closes the conn on any context error.
|
||||||
|
ctx, cancel := context.WithCancel(s.ctx)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
// Auto-subscribe to presence channel so this user appears online
|
// Auto-subscribe to presence channel so this user appears online
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ metadata:
|
|||||||
name: pusher-backend-policy
|
name: pusher-backend-policy
|
||||||
spec:
|
spec:
|
||||||
default:
|
default:
|
||||||
timeoutSec: 60
|
timeoutSec: 3600
|
||||||
connectionDraining:
|
connectionDraining:
|
||||||
drainingTimeoutSec: 30
|
drainingTimeoutSec: 30
|
||||||
targetRef:
|
targetRef:
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ metadata:
|
|||||||
name: pusher-backend-policy
|
name: pusher-backend-policy
|
||||||
spec:
|
spec:
|
||||||
default:
|
default:
|
||||||
timeoutSec: 60
|
timeoutSec: 3600
|
||||||
connectionDraining:
|
connectionDraining:
|
||||||
drainingTimeoutSec: 30
|
drainingTimeoutSec: 30
|
||||||
targetRef:
|
targetRef:
|
||||||
|
|||||||
Reference in New Issue
Block a user