mirror of
https://github.com/openlibrecommunity/olcrtc.git
synced 2026-05-26 07:08:11 +00:00
fix(jitsi): guard reconnect counter with mutex
This commit is contained in:
@@ -98,6 +98,7 @@ type Session struct {
|
||||
reconnecting atomic.Bool
|
||||
|
||||
reconnectCh chan struct{}
|
||||
reconnectMu sync.Mutex // guards reconnectWindowStart and reconnectCount
|
||||
reconnectWindowStart time.Time
|
||||
reconnectCount int
|
||||
localEpoch atomic.Uint32
|
||||
@@ -962,18 +963,21 @@ func (s *Session) requestReconnect(reason string) {
|
||||
|
||||
func (s *Session) handleReconnectAttempt(ctx context.Context) bool {
|
||||
now := time.Now()
|
||||
s.reconnectMu.Lock()
|
||||
if s.reconnectWindowStart.IsZero() || now.Sub(s.reconnectWindowStart) > reconnectWindow {
|
||||
s.reconnectWindowStart = now
|
||||
s.reconnectCount = 0
|
||||
}
|
||||
s.reconnectCount++
|
||||
count := s.reconnectCount
|
||||
s.reconnectMu.Unlock()
|
||||
|
||||
if s.reconnectCount > maxReconnects {
|
||||
if count > maxReconnects {
|
||||
s.signalEnded("jitsi reconnect limit reached")
|
||||
return true
|
||||
}
|
||||
|
||||
backoff := time.Duration(s.reconnectCount) * 2 * time.Second
|
||||
backoff := time.Duration(count) * 2 * time.Second
|
||||
if backoff > 30*time.Second {
|
||||
backoff = 30 * time.Second
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user