Skip to content

fix(hook-volume): bound the volume hook with a timeout and kill a hung child - #299

Closed
kiwipaulrob wants to merge 1 commit into
Sendspin:mainfrom
kiwipaulrob:fix/hook-volume-timeout
Closed

kiwipaulrob wants to merge 1 commit into
Sendspin:mainfrom
kiwipaulrob:fix/hook-volume-timeout

Conversation

@kiwipaulrob

@kiwipaulrob kiwipaulrob commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Problem

HookVolumeController.set_state() awaits proc.communicate() with no timeout and never kills the child. A volume hook that hangs — a busy or wedged ALSA device, a script waiting on stdin — blocks the caller forever and leaves the process behind. Every volume change spawns a fresh hook process and nothing bounds it, so one hung hook wedges the volume path and leaks a child each time it is re-entered.

Fix

Wrap the wait in asyncio.wait_for() (10 s bound) and, on timeout, kill and reap the child before raising RuntimeError — consistent with the existing non-zero-exit path, which already raises. The logical volume is not persisted when the hook fails, so settings cannot claim a volume the device never accepted.

Related: #274, which reports volume-hook invocations running concurrently and out of order. Ordering needs its own change, but a hook that never returns cannot be ordered at all.

Verification

  • New test in tests/test_hook_volume.py drives a hung process and asserts it is killed and reaped, that RuntimeError is raised, and that the volume is not persisted. It fails against the previous code.
  • pytest (full suite), ruff check, ruff format --check, mypy sendspin all clean.

Types of changes

  • Bugfix (non-breaking change which fixes an issue): bugfix
  • New feature (non-breaking change which adds functionality): new-feature
  • Breaking change (fix or feature that would cause existing functionality to change): breaking-change
  • Refactoring (no functional change): refactor
  • Documentation update: documentation
  • Maintenance (tooling, CI, dependencies): maintenance

…g child

set_state() awaited proc.communicate() with no timeout and never killed the
child. A hook that hangs (a busy or wedged ALSA device, a script waiting on
input) blocked the caller forever and left the process behind.

Wrap the wait in asyncio.wait_for() and, on timeout, kill and reap the child
before raising RuntimeError, so a hung hook fails fast and leaves nothing
running. Related: Sendspin#274, which reports volume-hook invocations running
concurrently and out of order -- ordering needs its own change, but a hook that
never returns cannot be ordered at all.
@github-actions github-actions Bot added the bugfix Fixes a bug label Oct 24, 2026

@balloob balloob left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apply a minimal fix. Don't extract constants or things like that. Drop the test.

@balloobbot balloobbot mentioned this pull request Oct 26, 2026
1 of 9 tasks
@balloob balloob closed this in #308 Oct 26, 2026
stefanfoulis pushed a commit to stefanfoulis/sendspin-cli that referenced this pull request Nov 13, 2026
# What does this implement/fix?

A hung volume hook blocked all later volume changes and left its process
behind. The hook now times out after 10 seconds, and its process is
killed. Minimal version of the fix by @kiwipaulrob.

**Related issue (if applicable):**

- Fixes Sendspin#299

## Types of changes

<!--
Tick exactly one box. CI (.github/workflows/pr-labels.yaml) applies the
matching label, and the release notes use it to sort this change.
-->

- [x] Bugfix (non-breaking change which fixes an issue): `bugfix`
- [ ] New feature (non-breaking change which adds functionality):
`new-feature`
- [ ] Enhancement to an existing feature: `enhancement`
- [ ] Breaking change (changes CLI options, settings, hooks or the
protocol in a way that is not backwards compatible): `breaking-change`
- [ ] Refactor (no behavior change): `refactor`
- [ ] Documentation only: `documentation`
- [ ] Maintenance / chore: `maintenance`
- [ ] CI / workflow change: `ci`
- [ ] Dependencies bump: `dependencies`

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
Co-authored-by: Paul Robertson <paularobertson@gmail.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix Fixes a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants