Sonos S1 (Gen1) players misdetected as S2 → householdId errors, and playback to S1 freezes sonn-core for ~21 s so the Miniserver reconnects and all zones stop (regression from beta.20)
Related to #119 (mixed S1/S2 setup), but this happens without any groups. The freeze (Finding 2) is a regression: worked with v4.0.0-beta.20, broken in beta.24. The S1→S2 misdetection (Finding 1) also exists in beta.20, but is harmless there.
Version / environment
- sonn-core v4.0.0-beta.24, built from tag, Docker (
--network host --privileged) - Host: ARM64 SBC (RK3588), Debian trixie
- Loxone Miniserver 15.5.3.4
- Previous version v4.0.0-beta.20 worked fine with the same setup
- All Sonos players on the latest available firmware
Setup – two separate Sonos households
| Household | Players | Firmware | householdId (local API /api/v1/players/local/info) |
|---|---|---|---|
S1 (swGen: 1) |
4× Connect:Amp | 57.23-74170 (11.16.1) / 57.23-83121 (11.16.2) | Sonos_<S1-household>.<suffix> |
S2 (swGen: 2) |
~15 players (Amp, Port, Connect, Playbar, Sub, Play:1) | 17.x / 27.x | Sonos_<S2-household>.<suffix> |
The two households have different householdIds. No groups between zones. Some players are powered off for energy saving – their fetch failed warnings are expected.
Behaviour
| Scenario | Result |
|---|---|
| S1 zone plays alone | OK |
| S1 zone plays, then S2 zone(s) started | OK, different sources possible |
| S1 + S2 playing, then any action on the S1 zone (source change etc.) | all playback stops |
| S2 zone plays, then S1 zone started | all playback stops |
Finding 1 – S1 players are detected as S2 (also present in beta.20)
All four S1 players answer the local API on port 1443 with HTTP 200 and correctly report "swGen":1 plus a valid householdId:
<S1-player-A> Sonos Connect:Amp 57.23-74170 (11.16.1) API1443=HTTP200 swGen=1 householdId=Sonos_<S1-household>.<suffix>
<S1-player-B> Sonos Connect:Amp 57.23-83121 (11.16.2) API1443=HTTP200 swGen=1 householdId=Sonos_<S1-household>.<suffix>
Nevertheless sonn-core selects the S2 backend for all of them and fails every ~6 s:
[INFO][Zones|StateController:Sonos] [generation=S2 host=<S1-player-A> zoneId=17] sonos state controller backend selected
[INFO][Zones|StateController:Sonos] [host=<S1-player-A> zoneId=17] sonos state controller connected
[WARN][Zones|StateController:Sonos] [host=<S1-player-A> message="Command failed: Missing required value:[0].householdId" zoneId=17] sonos state stream stopped
(same for all four S1 players – S2 players never show this error)
It looks like the detection treats "port 1443 API responds" as S2 instead of evaluating swGen.
The configured householdId is ignored: the correct householdId is set per zone in the sonn-core output settings. Tested both formats for one S1 zone – full API form (Sonos_<S1-household>.<suffix>) and short UPnP form (Sonos_<S1-household>) – no change, the error stays identical. The configured value is apparently not used by the state controller.
The output path does fall back correctly: the S2 WebSocket upgrade is rejected with 503 Service Unavailable, then SOAP is used.
Cross-check after downgrading to beta.20 (same data, same players): the misdetection and the householdId loop are identical in beta.20 (all four S1 players generation=S2, 7–8× Missing required value:[0].householdId within one minute) – but playback works:
[INFO][Output|Sonos] [zoneId=17] sending playback command uri=x-rincon-mp3radio://…/streams/17/current.mp3
[INFO][Output|Sonos] [action=SetAVTransportURI durationMs=24 host=<S1-player-A>:1400 status=200 zoneId=17] Sonos action succeeded
[WARN][Output|Sonos] [action=Play durationMs=1355 host=<S1-player-A>:1400 timeoutMs=2500 zoneId=17] Sonos action slow
No log gaps, no Miniserver reconnect, other zones keep playing. So the regression is in the playback path of beta.24, not in the detection.
Finding 2 – playback command to an S1 player freezes the whole process for ~21 s (regression, beta.24 only)
Right after SetAVTransportURI to the S1 player, the log is completely silent for ~21 s – even the otherwise continuous SPAM sendspin server/time messages (several per second) stop. This looks like the Node event loop is blocked, not like an async network wait.
13:01:15.452 [DEBUG][Output|Sonos] zoneId=17 sonos s2 connect failed: Upgrade rejected: 503 Service Unavailable
13:01:15.456 [INFO ][Output|Sonos] zoneId=17 sending playback command uri=x-rincon-mp3radio://<host>:7090/streams/17/current.mp3
13:01:15.463 [DEBUG][Output|Sonos] zoneId=17 Sonos soap request action=SetAVTransportURI service=AVTransport
---- no log output at all for 22 s ----
13:01:37.742 [DEBUG][LoxoneHttp|Processor] audio/cfg/speakertype/… <- Miniserver pushes full config again
13:01:37.770 [INFO ][Loxone|ConfigService] [players=0 updated=0] volume preset applied
13:01:38.246 [DEBUG][LoxoneHttp|Processor] audio/cfg/ready
13:01:47.764 [INFO ][Loxone|ConfigService] [players=17 updated=17] volume preset applied
Log lines per second: 13:01:14 → 21, 13:01:15 → 4, 13:01:16…13:01:36 → 0, 13:01:37 → 176.
Second reproduction, identical (here the Miniserver even does a full re-pairing):
13:05:17.142 [DEBUG][Output|Sonos] zoneId=17 Sonos soap request action=SetAVTransportURI service=AVTransport
---- no log output at all for 21 s ----
13:05:39.241 [DEBUG][LoxoneHttp|Dispatcher] dispatcher socket error: Parse Error: Invalid method encountered
13:05:39.257 [DEBUG][LoxoneHttp|WS] [total=1] ws connected
13:05:39.305 [DEBUG][LoxoneHttp|Processor] secure/hello … secure/init …
Interpretation: the freeze makes sonn-core miss the Miniserver keepalive → Miniserver reconnects and re-pushes the audio config → all zones are reset → all playback stops.
The freeze only occurs when a playback command is sent to an S1 player. A log taken while the S1 players were only online (state-stream error loop running, no playback) shows no gaps > 5 s and no Miniserver reconnect.
Minor
sonos client disconnect failed; closing its transport directly – Cannot read properties of undefined (reading 'disconnect') (player powered off)
Note
Native Sonos output is essential for S1 players – they don't support AirPlay, so AirPlay is no alternative for them.
Attachments (spam-level logs, redacted)
repro1-1301-redacted.txt– reproduction 1 (play on S1 zone 17 at 13:01:13)repro2-1305-redacted.txt– reproduction 2 (play on S1 zone 17 at 13:05:15)idle-1352-redacted.txt– S1 players online, no playback (state-stream error loop only)
Redaction: IPs → S1-player-A…D, sonncore-host, miniserver, host-NN; zone/room names → Zone-NN; RINCON/MAC → <devNN> / <macNN>; titles, artists, stations, URLs and tokens removed. Mappings are consistent across all three files.
Same here, and I think I can add the code-level causes. Setup: one Play:5 Gen1 (S1, swGen: 1,
57.23-83121 / 11.16.2) on a separate IoT subnet, sonn-core v4.0.0-beta.24 (Docker via Audioserver4Home on
LoxBerry, ARM64), no groups. The other zones are Squeezelite. Both findings from this issue reproduce, plus a third one.
🤖 marks interpretation.
1. Misdetection: swGen is never read
detectGeneration() in node-sonos (src/sonos/api/upnp/discovery.ts:24, unchanged on main / v0.3.0) returns
'S2' as soon as https://<host>:1443/api/v1/players/local/info answers 200. S1 firmware 11.x serves that endpoint
too and says so in the body:
{"device":{"model":"S5","modelDisplayName":"Play:5","softwareVersion":"57.23-83121","swGen":1, ...},
"householdId":"Sonos_…", ...}
The UPnP description on :1400 also carries <swGen>1</swGen>. Reading device.swGen from the probe response
(1 → S1) would fix the detection. The S2 backend then sends groupVolume:getVolume without a householdId, the S1
firmware answers ERROR_MISSING_PARAMETERS, and the state controller reconnects every ~6 s for good. The configured
householdId cannot help, because it never reaches that command.
2. The "freeze" is an uncaught exception that shuts the process down
In my logs the sequence is the same as in your two reproductions, but there is no silent gap. 4 ms after the SOAP
request comes an uncaught exception, then the regular shutdown, then a fresh bootstrap. Docker restarts the
container (RestartCount went to 3 in one morning):
07:30:56.663 [DEBUG][Output|Sonos] [message=timeout zoneId=18] sonos s2 connect failed
07:30:56.665 [INFO][Output|Sonos] [uri=x-rincon-mp3radio://<sonn-host>:7090/streams/18/current.mp3?prime=… zoneId=18] sending playback command
07:30:56.668 [DEBUG][Output|Sonos] [action=SetAVTransportURI service=AVTransport zoneId=18] Sonos soap request
07:30:56.672 [ERROR][Server] [message="WebSocket was closed before the connection was established" stack="Error: WebSocket was closed before the connection was established
at WebSocket.terminate (/app/node_modules/ws/lib/websocket.js:496:7)
at SonosWebSocketApi.discardSocket (/app/node_modules/@sonn-audio/node-sonos/dist/sonos/api/websocket.js:205:16)
at SonosWebSocketApi.disconnect (/app/node_modules/@sonn-audio/node-sonos/dist/sonos/api/websocket.js:186:14)
at SonosClient.disconnect (/app/node_modules/@sonn-audio/node-sonos/dist/sonos/client.js:95:24)
at /app/dist/adapters/outputs/sonos/sonosOutput.js:622:34
at async SonosOutput.tryS2 (/app/dist/adapters/outputs/sonos/sonosOutput.js:648:24)
…"] uncaught exception
07:30:56.701 [INFO][Loxone|UDPDiscovery] udp discovery listener stopped
… (all services stop)
07:30:59.252 [INFO][Server] service zones stopped
07:31:01.869 [INFO][Server] [env=development loxoneEnabled=true] bootstrapping audio server
The same happened once with Upgrade rejected: 503 Service Unavailable instead of the timeout, from
tryApplyVolume, so it is not tied to the play command.
How it happens:
SonosOutput.ensureS2Client()(src/adapters/outputs/sonos/sonosOutput.ts:737) wrapsclient.connect()in a 4 s timeout and callsawait client.disconnect()in the catch.SonosWebSocketApi.disconnect()→discardSocket()(node-sonossrc/sonos/api/websocket.ts:224) callsws.removeAllListeners()and thenws.terminate(), because the socket is notCLOSED.- On a socket that is still
CONNECTING(handshake not finished at the timeout, or anunexpected-responselistener keeping the request open after the 503),terminate()aborts the handshake. ws then emitserror("WebSocket was closed before the connection was established") on a socket that no longer has an error listener. - That is an uncaught exception, and
src/runtime/shutdown.tscallsshutdown()on it. All zones stop and the Miniserver reconnects and pushes its config again.
The try/catch around client.disconnect() cannot catch it, because the event fires asynchronously. A fix in
discardSocket would be to attach a no-op error listener after removeAllListeners() (or not remove it), before
terminate().
🤖 Why the S2 handshake fails in the first place: the Gen1 hardware is slow on TLS. From the sonn host I measured
0.6–3.5 s for a single GET /api/v1/players/local/info on :1443 (vs. 0.16 s for the :1400 description). Together
with the endless state-controller reconnects (finding 1), the handshake either runs past the 4 s timeout or the
speaker answers 503. So finding 1 feeds finding 2. 🤖 For an S1 speaker the output should not try S2 at all once
the generation is known.
On the beta.20 regression: I cannot explain it from the code. discardSocket (node-sonos 0.2.4 and 0.3.0),
SonosClient.disconnect, the client.disconnect() call in ensureS2Client and the uncaughtException handler are
the same in beta.20 and beta.24. 🤖 My guess is that the timing (503 / timeout during the handshake) simply did not
occur there. Container uptime or docker inspect -f '{{.RestartCount}}' after a "freeze" would show whether you see
the same restart.
3. With the Sonos state controller, our own radio stream is taken for an external source
Not in this issue yet. Before I switched the zone's state controller to internal, the first radio start went out fine via SOAP, and 0.5 s later the zone gave the speaker up and stopped its own session:
07:15:29.504 [INFO][Output|Sonos] [uri=x-rincon-mp3radio://<sonn-host>:7090/streams/18/current.mp3?prime=1795763724258 zoneId=18] Sonos playback started
07:15:29.992 [INFO][Audio|Engine] [zoneId=18] audio session stopped
07:15:29.994 [INFO][Zones|Manager] [controller=sonos mediaUrl=x-rincon-mp3radio://http://<sonn-host>:7090/streams/18/current.mp3?prime=1795763724258 source="…" zoneId=18] zone yielded its speaker to an external source
07:15:32.432 [INFO][Http|Streams] … no active session for stream request
The speaker reports the URI back with a second scheme, x-rincon-mp3radio://http://…. isOwnStreamUrl()
(src/domain/outputs/sonosIdentity.ts) only replaces the outer scheme, so it parses http://http://<sonn-host>:7090/…,
the host does not match, and noteSpeakerSource() raises an external takeover. Checked in the running container:
isOwnStreamUrl('x-rincon-mp3radio://<sonn-host>:7090/streams/18/current.mp3', base) → true
isOwnStreamUrl('x-rincon-mp3radio://http://<sonn-host>:7090/streams/18/current.mp3', base) → false
isOwnStreamUrl('http://<sonn-host>:7090/streams/18/current.mp3', base) → true
Stripping a nested http(s):// after the outer scheme would fix it. The service/object-id checks on dev (#430)
don't cover this case, because the SOAP path doesn't return that container metadata. 🤖 It probably hits S2 speakers
too whenever radio goes over SOAP and the state comes back with this URI form. I have only seen it on S1.
Workaround I'm about to test
State controller internal (avoids finding 3), and a REJECT rule (TCP reset, not DROP) for the sonn host → speaker
:1443. 🤖 Then the S2 connect fails immediately, the socket is already CLOSED when discardSocket runs, and the
crash path is not reached. Playback goes over SOAP on :1400, which works. DROP would run into the 4 s timeout again.
I'll report back.
Follow-up: the workaround holds. Same setup as above (Play:5 Gen1, S1, beta.24).
- State controller internal for the zone.
- REJECT (not DROP) for TCP from the sonn host to the speaker's :1443, now on the router instead of the host. A
request to
https://<speaker>:1443/from the sonn host fails after <1 ms, :1400 still answers normally.
With that, every play start logs
[DEBUG][Output|Sonos] [message="fetch failed" zoneId=18] sonos s2 connect failed (21 ms after "playback started")
[INFO][Output|Sonos] [uri=x-rincon-mp3radio://<sonn-host>:7090/streams/18/current.mp3?prime=… zoneId=18] sending playback command
[INFO][Output|Sonos] [uri=… zoneId=18] Sonos playback started
and playback runs over SOAP. Tested with radio (several sessions, longest ~7 min) and a full album from the local
library with gapless track changes. No uncaught exception, RestartCount unchanged since the rule went in. Before
it, the container restarted three times in one morning.
Two notes for anyone copying this:
- DROP does not help. The S2 connect then runs into the 4 s timeout and the crash path is back.
- With the internal controller the core does not notice when the speaker stops on its own; it keeps reporting
play. Acceptable for me, but it is a trade-off.
The dropouts I saw in my first tests were the speaker's Wi-Fi (ping stalls up to 1.4 s), unrelated to this issue. They went away after repositioning the speaker.
🤖 So for S1 speakers on beta.24 the crash is avoidable from the outside until findings 1–3 are fixed. The
discardSocket error listener (finding 2) would also protect S2 users who hit a slow or 503 handshake.
Thanks for the detailed analysis – the uncaught exception / Docker restart explains the ~21 s gap in my logs much better than my "event loop freeze" interpretation.
Regarding the regression: I'm back on v4.0.0-beta.20 (same data, same players). Test today: S1 zone (Connect:Amp) and S2 zone playing in parallel, switching radio stations back and forth on both zones for several minutes → RestartCount=0, StartedAt unchanged. On beta.24 exactly this scenario crashed every time.
The S1→S2 misdetection and the householdId loop are also present in beta.20, but there they're harmless – playback via SOAP works and nothing crashes. So it seems beta.24 introduced the path that ends in ws.terminate() on the still-connecting socket.
Thanks both, especially for the code-level analysis. All three are fixed on dev: the uncaught exception when a Sonos connection fails during the handshake (in node-sonos 0.3.1 and in our output), S1 speakers are now detected from the swGen they report and no longer tried over the S2 API, and our stream reported as x-rincon-mp3radio://http://… is no longer taken for another source. You can drop the REJECT rule and switch the state controller back to Sonos once you're on the next dev build. I'd like to hear whether it holds up on your S1 speakers.