Audio Server fails to set initial volume / Sonos S2 connection timing issue
Description: The logs indicate a timing issue (race condition) during the startup sequence. The Audio Server attempts to initialize the zones and set the default volume before the network discovery (SSDP) for the Sonos speakers has completed. Log Analysis: Connection Failure: During startup, the Audio Server tries to connect to the zones but fails immediately: [DEBUG][Output|Sonos] [message="Failed to connect" zoneId=XX] sonos s2 connect failed Missing Output: Because the connection is not yet established, the zone manager reports activeOutput=null. Consequently, any volume commands sent at this point have no valid target and are ignored. Delayed Discovery: The SSDP discovery responses (UPnP) from the Sonos units arrive several milliseconds after the initial connection attempt has already failed and the "startup complete" signal was triggered. Conclusion: The startup volume is not applied because the activeOutput is still null during the boot sequence. The system does not appear to re-trigger or "catch up" the volume setting once the Sonos devices are successfully discovered via SSDP a few moments later.
I’ve made a fix for this in commit 6b41943 (fix: retry pending sonos volume).
The conclusion was partly correct: the issue was not specifically caused by activeOutput === null, because when there is no active output, the zone volume code dispatches to all normal outputs. The actual problem was that the startup volume was only offered once during boot. If Sonos/SSDP was not ready at that moment, that value was dropped and there was no later catch-up.
The Sonos output now stores the desired volume as a pending volume, tries S2 first and then SOAP, and retries with backoff until discovery/endpoints are available. On a later play(), that pending volume is also applied again.
Not live-tested on real Sonos hardware; npm test and npm run build are green.
You can test it by using the dev branch or bij using the latest dev container
also available on the latest beta