From b63192a376ce2f67a8a0d8036db7d256108fd415 Mon Sep 17 00:00:00 2001 From: Paul Wells Date: Sun, 8 Sep 2024 19:53:19 -0700 Subject: [PATCH] add config for signal retry (#2989) --- pkg/config/config.go | 2 ++ pkg/service/rtcservice.go | 23 +---------------------- 2 files changed, 3 insertions(+), 22 deletions(-) diff --git a/pkg/config/config.go b/pkg/config/config.go index a8b03f598..fc57b23f0 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -295,6 +295,7 @@ type SignalRelayConfig struct { MinRetryInterval time.Duration `yaml:"min_retry_interval,omitempty"` MaxRetryInterval time.Duration `yaml:"max_retry_interval,omitempty"` StreamBufferSize int `yaml:"stream_buffer_size,omitempty"` + ConnectAttempts int `yaml:"connect_attempts,omitempty"` } // RegionConfig lists available regions and their latitude/longitude, so the selector would prefer @@ -569,6 +570,7 @@ var DefaultConfig = Config{ MinRetryInterval: 500 * time.Millisecond, MaxRetryInterval: 4 * time.Second, StreamBufferSize: 1000, + ConnectAttempts: 3, }, PSRPC: rpc.DefaultPSRPCConfig, Keys: map[string]string{}, diff --git a/pkg/service/rtcservice.go b/pkg/service/rtcservice.go index 851816907..ef14da079 100644 --- a/pkg/service/rtcservice.go +++ b/pkg/service/rtcservice.go @@ -42,13 +42,6 @@ import ( "github.com/livekit/psrpc" ) -const ( - // TODO: make these configurable - initialBackoffSeconds = 1 - maxBackoffSecondsPow = 6 // 64 seconds - startConnectionMaxTries = 3 -) - type RTCService struct { router routing.MessageRouter roomAllocator RoomAllocator @@ -236,27 +229,13 @@ func (s *RTCService) ServeHTTP(w http.ResponseWriter, r *http.Request) { // give it a few attempts to start session var cr connectionResult var initialResponse *livekit.SignalResponse - for attempt := 0; attempt < startConnectionMaxTries && r.Context().Err() == nil; attempt++ { + for attempt := 0; attempt < s.config.SignalRelay.ConnectAttempts; attempt++ { connectionTimeout := 3 * time.Second * time.Duration(attempt+1) ctx := utils.ContextWithAttempt(r.Context(), attempt) cr, initialResponse, err = s.startConnection(ctx, roomName, pi, connectionTimeout) if err == nil || errors.Is(err, context.Canceled) { break } - - if attempt < startConnectionMaxTries-1 { - // exponential backoff delay. powers of 2. - backoffDelay := time.NewTimer(time.Duration(initialBackoffSeconds<