srt: auto-restart listener on transient UDP errors#5712
Open
JohanG-LAS wants to merge 1 commit intobluenviron:mainfrom
Open
srt: auto-restart listener on transient UDP errors#5712JohanG-LAS wants to merge 1 commit intobluenviron:mainfrom
JohanG-LAS wants to merge 1 commit intobluenviron:mainfrom
Conversation
The MediaMTX SRT server would permanently shut down whenever the underlying gosrt listener returned any non-deadline error from its ReadFrom loop (e.g. a transient `read udp: network is unreachable` caused by an Azure Accelerated Networking VF flap or any other short-lived UDP socket fault). gosrt marks the listener as done on such errors and Accept2() returns the error; MediaMTX then logged it and broke out of its server loop, leaving SRT unavailable until the process was restarted manually. Treat any non-ErrListenerClosed listener failure as recoverable: close the dead listener, retry srt.Listen with bounded exponential backoff plus jitter, and re-spawn the listener goroutine on success. ErrListenerClosed (returned during graceful shutdown) and context cancellation continue to exit the loop cleanly. Existing live connections, the server goroutine, the connection map, the API, and metrics are untouched: only the accept side is recreated. A package-level srtListen indirection allows tests to substitute a fake listener; three new tests cover the restart-on-transient, no-restart-on-closed, and give-up-on-context-cancel paths. Made-with: Cursor
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5712 +/- ##
==========================================
+ Coverage 62.08% 63.23% +1.14%
==========================================
Files 214 217 +3
Lines 17602 18280 +678
==========================================
+ Hits 10929 11560 +631
- Misses 5766 5783 +17
- Partials 907 937 +30 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Cloud providers are regularly doing VM live migrations, causing VM's to freeze during a couple of seconds. See Azure and Google
TCP transport protocols often handles these "outages" well, but UDP protocols can struggle.
The MediaMTX SRT server would permanently shut down whenever the underlying gosrt listener returned any non-deadline error from its ReadFrom loop (e.g. a transient
read udp: network is unreachable).gosrt marks the listener as done on such errors and Accept2() returns the error. MediaMTX then logged it and broke out of its server loop, leaving SRT unavailable until the process was restarted manually.
Fix
Treat any non-ErrListenerClosed listener failure as recoverable: close the dead listener, retry srt.Listen with bounded exponential backoff plus jitter, and re-spawn the listener goroutine on success. ErrListenerClosed (returned during graceful shutdown) and context cancellation continue to exit the loop cleanly. Existing live connections, the server goroutine, the connection map, the API, and metrics are untouched: only the accept side is recreated.
Test
A package-level srtListen indirection allows tests to substitute a fake listener; three new tests cover the restart-on-transient, no-restart-on-closed, and give-up-on-context-cancel paths.
Made-with: Cursor