Skip to content

Fix AirPlay Receiver losing audio after quick reconnects#4785

Draft
MarvinSchenkel wants to merge 2 commits into
devfrom
fix/airplay-receiver-stop-play-race
Draft

Fix AirPlay Receiver losing audio after quick reconnects#4785
MarvinSchenkel wants to merge 2 commits into
devfrom
fix/airplay-receiver-stop-play-race

Conversation

@MarvinSchenkel

Copy link
Copy Markdown
Contributor

What does this implement/fix?

AirPlay Receiver could report that playback started while producing no audio after a quick session reconnect. Session teardown stopped the target player in a background task, so the delayed stop could complete after the next session had already started playback and kill the new stream.

  • Keep track of the pending stop task
  • Wait for that stop before starting playback for the next AirPlay session
  • Continue playback after a failed stop while logging the failure
  • Add tests for quick reconnects, normal starts, and failed stops

This was reproduced with an asynchronous simulation. Live hardware verification requires reporter testing because the bundled shairport-sync cannot run in the available macOS test environment.

Related issue (if applicable):

Types of changes

  • 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
  • New music/player/metadata/plugin provider — new-provider
  • Breaking change (fix or feature that would cause existing functionality to not work as expected) — breaking-change
  • Refactor (no behaviour change) — refactor
  • Documentation only — documentation
  • Maintenance / chore — maintenance
  • CI / workflow change — ci
  • Dependencies bump — dependencies

Checklist

  • The code change is tested and works locally.
  • pre-commit run --all-files passes.
  • pytest passes, and tests have been added/updated under tests/ where applicable.
  • For changes to shared models, the companion PR in music-assistant/models is linked.
  • For changes affecting the UI, the companion PR in music-assistant/frontend is linked.
  • I have read and complied with the project's AI Policy for any AI-assisted contributions.
  • I have raised a PR against the documentation repository targeting the main or beta branch as appropriate.

…yback

A quick stop->play bounce from the AirPlay sender (e.g. session
reconnect) raced the fire-and-forget cmd_stop from the previous session:
_clear_active_player already released the claim, so the new play_media
was issued immediately and the late stop then killed the freshly started
stream, leaving the player 'playing' without audio (#5771).

Keep a handle on the pending stop task and let playback start await it
before calling play_media, so stop and play are always ordered.
@MarvinSchenkel

Copy link
Copy Markdown
Contributor Author

Awaiting user confirmation in the linked issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant