Skip to content

nest: improve stream extension resilience and token refresh#2128

Open
PrutsMeneer wants to merge 1 commit intoAlexxIT:masterfrom
PrutsMeneer:fix/nest-extend-loop
Open

nest: improve stream extension resilience and token refresh#2128
PrutsMeneer wants to merge 1 commit intoAlexxIT:masterfrom
PrutsMeneer:fix/nest-extend-loop

Conversation

@PrutsMeneer
Copy link
Copy Markdown

@PrutsMeneer PrutsMeneer commented Mar 3, 2026

Summary

  • make Nest token refresh deterministic by storing credentials in API and calling OAuth refresh directly
  • make ExtendStream retry behavior more robust for transient 401/409/429 responses
  • keep extend timer loop running after transient extend errors to avoid unnecessary stream reconnects

Why

When stream extension fails once, the stream can expire and streams reconnect starts ([streams] retry=...). These changes reduce avoidable drops by improving retry and refresh behavior.

Testing

  • go test ./pkg/nest

@PrutsMeneer
Copy link
Copy Markdown
Author

bug at: #2108

MechanicalCoderX added a commit to MechanicalCoderX/go2rtc that referenced this pull request Mar 28, 2026
StartExtendStreamTimer used a one-shot timer that fired once at T+4min,
extended the stream for another 5 minutes, then exited — leaving no timer
running for subsequent extensions. The stream expired at ~10 minutes and
required a full WebRTC reconnect every cycle.

Replace the one-shot timer with a continuous goroutine loop that
reschedules itself from the updated StreamExpiresAt after each extend,
keeping the stream alive indefinitely. The loop also continues on
transient errors rather than stopping, preventing avoidable expiry.

Also adds retry logic to ExtendStream (401 → token refresh, 409/429 →
exponential backoff) and stores OAuth credentials on the API struct so
refreshToken() works correctly after the first token rotation.

Fixes AlexxIT#2108, mirrors approach from PR AlexxIT#2128.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant