/
/
# What does this implement/fix?
Moving a playing Spotify Connect session from one player to another
could kill the session instead of handing it over: playback stopped, the
Spotify app dropped the device ("no longer active device" in the log),
and the player you just started on stayed silent. Playing again worked,
which is what made it look intermittent.
The source is an ordering bug in the plugin's handover. When the source
is selected on a new player, the plugin first stopped the previous
player and only claimed ownership afterwards. Stopping the old player
tears its stream down, and that teardown still carried the *old* stream
session id — which, because the new claim had not been written yet,
passed the "is this callback stale?" guard and released the Spotify
session the new player was about to use.
Claiming ownership before stopping the previous player restores what the
code already intended: the teardown is recognised as stale and leaves
the live session alone.
- Write the queue claim before kicking the previous player in
`on_source_selected`
- Regression test that fails without the fix (the old player's teardown
completes inside the awaited stop)
## Types of changes
- [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`
- [ ] 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
- [x] The code change is tested and works locally.
- [x] `pre-commit run --all-files` passes.
- [x] `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.
- [x] I have read and complied with the project's [AI
Policy](https://github.com/music-assistant/.github/blob/main/AI_POLICY.md)
for any AI-assisted contributions.
- [ ] I have [raised a PR against the documentation
repository](https://github.com/music-assistant/music-assistant.io/blob/main/CONTRIBUTING.md)
targeting the main or beta branch as appropriate.