Skip to content

client: fix race that drops a group's subscription callbacks, making … - #145

Open
vanackere wants to merge 1 commit into
music-assistant:mainfrom
vanackere:fix/race-double-subscribe-on-group
Open

client: fix race that drops a group's subscription callbacks, making …#145
vanackere wants to merge 1 commit into
music-assistant:mainfrom
vanackere:fix/race-double-subscribe-on-group

Conversation

@vanackere

Copy link
Copy Markdown

…the speaker appear unresponsive

_handle_groups_event is synchronous, but _setup_group is scheduled as an async task. When two group events for the same id arrive back-to-back — in practice this happens whenever the Sonos household publishes a quick burst of topology updates (a player joining or leaving a group, a speaker coming back online after a network blip, a controller reload triggering an immediate refresh) — the second event observes
group_id not in self._groups (the first task has not run yet), and a second _setup_group task is queued. Both tasks then call .subscribe() for the same event id, and the second one silently overwrites the first listener in _listeners. The original listener never fires again, so events for that group stop being processed — to the user, the speaker stops reflecting playback state and looks frozen or disappears from the controller.

Fix: insert the SonosGroup into self._groups synchronously before scheduling _setup_group, so a racing event sees the group as known and takes the update_data path instead of queuing a duplicate setup.

…the speaker appear unresponsive

`_handle_groups_event` is synchronous, but `_setup_group` is scheduled as
an async task. When two group events for the same id arrive back-to-back —
in practice this happens whenever the Sonos household publishes a quick
burst of topology updates (a player joining or leaving a group, a speaker
coming back online after a network blip, a controller reload triggering
an immediate refresh) — the second event observes
`group_id not in self._groups` (the first task has not run yet), and a
second `_setup_group` task is queued. Both tasks then call `.subscribe()`
for the same event id, and the second one silently overwrites the first
listener in `_listeners`. The original listener never fires again, so
events for that group stop being processed — to the user, the speaker
stops reflecting playback state and looks frozen or disappears from the
controller.

Fix: insert the `SonosGroup` into `self._groups` synchronously before
scheduling `_setup_group`, so a racing event sees the group as known
and takes the `update_data` path instead of queuing a duplicate setup.
@vanackere

Copy link
Copy Markdown
Author

Adding some context: in my household one of the players (a Sonos Roam) was offline. After restarting the Music Assistant Sonos integration, two of the active speakers (Living Room, Office) consistently failed to register with the provider — they would only appear as their AirPlay siblings, never as Sonos players. The log carried a single
ERROR aiosonos.api.namespaces._base: Duplicate subscription detected for RINCON_<vanished_player_uuid>:<group_id> line per restart.

I'm not certain why an offline player in VanishedDevices makes the household publish topology updates fast enough to trigger the race (the offline player's UUID still appears as the coordinator id of an active group, which may be enough to make Sonos emit a quick correction event), but with this fix the affected speakers register
correctly even with the Roam still offline, and the Duplicate subscription detected log line is gone.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant