Harden stream process restarts: exponential backoff + ALSA readiness gate#1097
Open
stamateviorel wants to merge 2 commits into
Open
Harden stream process restarts: exponential backoff + ALSA readiness gate#1097stamateviorel wants to merge 2 commits into
stamateviorel wants to merge 2 commits into
Conversation
process_monitor restarted a crashing child in a tight zero-delay loop: a process that dies instantly (e.g. its ALSA output device cannot be opened) gets respawned as fast as the loop runs, flooding logs and wearing the SD card. Track consecutive fast failures and back off exponentially (2s..30s), resetting once a run survives 10 seconds. Signed-off-by: Stamate Viorel <stamate.viorel@gmail.com> Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
When the monitored player exits because its loopback is still held (a not-yet-released previous instance, or the dmix state from micro-nova#957), every respawn dies instantly with EINVAL and the stream stays silent - we saw a 5.5h outage from one stream re-assign. If the monitored command plays to an ALSA loopback (-o lb*), probe the device with a 1s silent aplay (the same open path the player uses) before each spawn and wait quietly until it opens. On the first failed probe, log the current /dev/snd holders via fuser so the journal explains the wedge; after four failed probes, kill a stale leftover player process that targets the same device (strict match on the binary name and exact -o argument, never the monitor's own child). Processes without an -o lb* argument are completely unaffected. Signed-off-by: Stamate Viorel <stamate.viorel@gmail.com> Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
What does this change intend to accomplish?
Two related robustness fixes for
streams/process_monitor.py:Exponential restart backoff. The monitor restarted a crashing child in a tight zero-delay loop — a process that dies instantly (e.g. its ALSA device can't be opened) gets respawned as fast as the loop runs, flooding logs and wearing the SD card. Fast failures now back off 2s→30s, resetting once a run survives 10 seconds.
ALSA readiness gate. When the monitored player exits because its loopback is still held (a not-yet-released previous instance, or the dmix state from Spotify controlled loopback getting into a bad state #957), every respawn dies instantly with EINVAL and the stream stays silent — we measured a 5.5-hour outage from one stream re-assign. If the monitored command plays to an ALSA loopback (
-o lb*), the monitor now probes the device with a 1s silentaplay(the same open path the player uses) before each spawn and waits quietly until it opens. On the first failed probe it logs the current/dev/sndholders viafuserso the journal explains the wedge; after four failed probes it kills a stale leftover player that targets the same device (strict match on binary name + exact-oargument, never its own child). Commands without-o lb*(e.g. alsaloop) are completely unaffected.Both are running in production on a real AmpliPi; the gate has already fired twice (loopback briefly held at service start) and recovered in one 2-second retry instead of crash-looping.
Checklist
aplaythrough a service restart)python -m py_compileclean; happy to fix anything CI flags)