core icon indicating copy to clipboard operation
core copied to clipboard

Startup hangs after "spotify manager reloaded" when a Sonos zone speaker is powered off; never recovers

Open logol01 opened this issue 1 week ago • 10 comments

Version: sonn core v4.0.0-beta.24 (Docker), 10 zones, several on Sonos speakers

Steps

  1. Power off one Sonos speaker (here the speaker of zone 16 "WC").
  2. docker restart sonn-core.

What happens

  • Startup stops after the log line spotify manager reloaded. Nothing else is logged after that line.
  • The admin UI and API on :7090 stay unreachable and Loxone gets no answers.
  • The reconnect timer for an unreachable speaker (about 5 s) never fires, which looks like a blocked event loop or an await with no timeout during startup.
  • Powering the speaker back on does not recover the process.
  • A second docker restart with all Sonos speakers powered on starts normally.

Expected An unreachable speaker should not block startup. Its zone should come up as offline and keep retrying in the background.

I can reproduce this and provide a full DEBUG log of the hang or other diagnostics if useful.

logol01 avatar Nov 28 '26 11:11 logol01

Thanks. I couldn't reproduce this here: with an unreachable Sonos speaker the server finishes starting after about 15 seconds and keeps retrying the speaker in the background. Could you send the full DEBUG log you offered, from the start until it hangs? If the container restarted or exited in between, docker inspect -f '{{.RestartCount}} {{.State.ExitCode}}' sonn-core would help too. The dev build also has a fix for a crash when a Sonos connection fails halfway (#444), which may well be the same thing.

rudyberends avatar Nov 28 '26 16:11 rudyberends

Reproduced it with the full DEBUG log (v4.0.0-beta.24, the image I run is a local tag of that build).

Steps: powered off the Sonos One of zone 16 "WC" (192.168.178.49), then docker restart sonn-core at 21:03:53Z.

Result: the server boots, registers all 10 zones, logs spotify manager reloaded at 21:04:04.436Z — and then nothing at all is logged any more, not even the per-second SPAM notifier lines that are otherwise constant. The sonos reconnect scheduled (delayMs=5000) for zone 16 never fires. I waited more than 3 minutes. During that time the admin UI on :7090 was not reachable.

docker inspect afterwards: RestartCount=0 ExitCode=0 Status=running StartedAt=2026-11-28T21:03:59Z. So the process does not crash or exit.

Recovery: as soon as I powered the WC speaker back on, sonn became reachable on :7090 again by itself, without a restart. So it looks less like a dead event loop and more like startup awaiting something on the unreachable speaker (192.168.178.49) without a timeout. Note that the host is powered off and not just refusing connections, so TCP connects to it hang instead of failing fast. Once the speaker answers, the await completes and bootstrap continues.

Notable points in the log:

  • Shutdown before the restart: service zones stop timed out (6000 ms).
  • Zone 16 is the last state controller to finish: detection takes ~4 s and ends with generation=unknown, then fetch failed, reconnect scheduled. Right after that come zones registered and the second spotify manager reloaded, and then the log goes silent.
  • All other 9 zones (all S2) connect normally within ~2 s.

Relevant lines (non-SPAM, IDs removed):

[2026-11-28T21:03:59.529Z][WARN][Server] [timeoutMs=6000] service zones stop timed out
[2026-11-28T21:04:00.423Z][INFO][Server] [env=development loxoneEnabled=true] bootstrapping audio server
[2026-11-28T21:04:00.513Z][INFO][Zones|StateController:Sonos] [generation=S2 host=192.168.178.126 zoneId=14] sonos state controller backend selected
[2026-11-28T21:04:00.522Z][INFO][Zones|StateController:Sonos] [generation=S2 host=192.168.178.38 zoneId=13] sonos state controller backend selected
[2026-11-28T21:04:00.529Z][INFO][Zones|StateController:Sonos] [generation=S2 host=192.168.178.39 zoneId=12] sonos state controller backend selected
[2026-11-28T21:04:00.540Z][INFO][Zones|StateController:Sonos] [generation=S2 host=192.168.178.106 zoneId=18] sonos state controller backend selected
[2026-11-28T21:04:00.544Z][INFO][Zones|StateController:Sonos] [generation=S2 host=192.168.178.41 zoneId=9] sonos state controller backend selected
[2026-11-28T21:04:00.550Z][INFO][Zones|StateController:Sonos] [generation=S2 host=192.168.178.134 zoneId=10] sonos state controller backend selected
[2026-11-28T21:04:00.567Z][INFO][Zones|StateController:Sonos] [generation=S2 host=192.168.178.42 zoneId=15] sonos state controller backend selected
[2026-11-28T21:04:00.578Z][INFO][Zones|StateController:Sonos] [generation=S2 host=192.168.178.37 zoneId=11] sonos state controller backend selected
[2026-11-28T21:04:00.658Z][DEBUG][Content|SpotifyManager] [accounts=3] spotify manager reloaded
[2026-11-28T21:04:00.660Z][INFO][Zones|StateController:Sonos] [host=192.168.178.126 zoneId=14 zoneName="Flur Keller"] sonos state controller connected
[2026-11-28T21:04:00.660Z][INFO][Zones|StateControllers] [controller=sonos zoneId=14] state controller started
[2026-11-28T21:04:00.677Z][INFO][Zones|StateController:Sonos] [host=192.168.178.39 zoneId=12 zoneName="Flur OG"] sonos state controller connected
[2026-11-28T21:04:00.678Z][INFO][Zones|StateControllers] [controller=sonos zoneId=12] state controller started
[2026-11-28T21:04:00.679Z][INFO][Zones|StateController:Sonos] [host=192.168.178.38 zoneId=13 zoneName="Flur EG"] sonos state controller connected
[2026-11-28T21:04:00.679Z][INFO][Zones|StateControllers] [controller=sonos zoneId=13] state controller started
[2026-11-28T21:04:00.710Z][INFO][Zones|StateController:Sonos] [host=192.168.178.106 zoneId=18 zoneName=Garten] sonos state controller connected
[2026-11-28T21:04:00.710Z][INFO][Zones|StateControllers] [controller=sonos zoneId=18] state controller started
[2026-11-28T21:04:00.779Z][INFO][Zones|StateController:Sonos] [host=192.168.178.41 zoneId=9 zoneName=Bad] sonos state controller connected
[2026-11-28T21:04:00.779Z][INFO][Zones|StateControllers] [controller=sonos zoneId=9] state controller started
[2026-11-28T21:04:00.786Z][INFO][Zones|StateController:Sonos] [host=192.168.178.134 zoneId=10 zoneName=Büro] sonos state controller connected
[2026-11-28T21:04:00.787Z][INFO][Zones|StateControllers] [controller=sonos zoneId=10] state controller started
[2026-11-28T21:04:00.813Z][INFO][Zones|StateController:Sonos] [host=192.168.178.42 zoneId=15 zoneName=Schlafzimmer] sonos state controller connected
[2026-11-28T21:04:00.814Z][INFO][Zones|StateControllers] [controller=sonos zoneId=15] state controller started
[2026-11-28T21:04:00.818Z][INFO][Zones|StateController:Sonos] [host=192.168.178.37 zoneId=11 zoneName=Esszimmer] sonos state controller connected
[2026-11-28T21:04:00.819Z][INFO][Zones|StateControllers] [controller=sonos zoneId=11] state controller started
[2026-11-28T21:04:00.930Z][INFO][Zones|StateController:Sonos] [generation=S2 host=192.168.178.40 zoneId=17] sonos state controller backend selected
[2026-11-28T21:04:02.174Z][INFO][Zones|StateController:Sonos] [host=192.168.178.40 zoneId=17 zoneName=Wohnzimmer] sonos state controller connected
[2026-11-28T21:04:02.175Z][INFO][Zones|StateControllers] [controller=sonos zoneId=17] state controller started
[2026-11-28T21:04:04.357Z][INFO][Zones|StateController:Sonos] [generation=unknown host=192.168.178.49 zoneId=16] sonos state controller backend selected
[2026-11-28T21:04:04.427Z][WARN][Zones|StateController:Sonos] [host=192.168.178.49 message="fetch failed" zoneId=16] sonos state controller failed to start
[2026-11-28T21:04:04.428Z][INFO][Zones|StateController:Sonos] [delayMs=5000 host=192.168.178.49 zoneId=16] sonos reconnect scheduled
[2026-11-28T21:04:04.428Z][INFO][Zones|StateControllers] [controller=sonos zoneId=16] state controller started
[2026-11-28T21:04:04.428Z][INFO][Zones|Manager] [count=10] zones registered
[2026-11-28T21:04:04.436Z][DEBUG][Content|SpotifyManager] [accounts=3] spotify manager reloaded

I can send the complete log (≈5,700 lines incl. SPAM) as a file if that helps, and I'm happy to test the dev build with the same steps.

logol01 avatar Nov 28 '26 21:11 logol01

Retested on 4.0.0-beta.25+dev-20261128174634 with one Sonos (S2) zone powered off before a container restart.

Result: startup no longer waits forever, but it is blocked for exactly 180 s by the single unreachable speaker. During that time the HTTP gateway (7090) and the Loxone servers (7091/7095) are not listening, so the Miniserver/app cannot reach the audio server at all and no zone can be used.

Timeline (UTC, from docker logs -t):

09:21:37  bootstrapping (speaker ON)  -> 09:21:39 startup complete   (~2 s)
09:24:24  speaker powered OFF
09:26:35  restart: bootstrapping audio server
09:26:42  [Zones|StateController:Sonos] zoneId=16 message="fetch failed" sonos state controller failed to start
09:26:42  [Zones|Manager] count=10 zones registered
          ... nothing listening for 3 minutes ...
09:29:42  [Http] port=7090 http gateway listening
09:29:42  [Server] startup complete
09:29:48 - 09:35:41  zone 16 "fetch failed", retried with backoff (fine, other zones work)
09:32:53  other zone plays a room favorite normally
09:36:05  speaker powered ON
09:36:41  zone 16 sonos state controller connected

Same pattern last night: zones registered 00:56:01 -> startup complete 00:59:01 (again exactly 180 s).

So the background retry after startup works well. The remaining issue is that bootstrap waits for every Sonos output before starting the HTTP/Loxone listeners. Could the listeners start right after zones registered, with unreachable outputs handled only by the background reconnect?

logol01 avatar Nov 29 '26 12:11 logol01

Thanks for retesting, the 180 s is a clear lead. I can't reproduce it here: with a Sonos speaker on the same subnet that doesn't answer at all, startup completes in about 8 seconds, with the same "generation unknown" and "fetch failed" as in your log. So something else in your setup waits those 3 minutes. Could you send the full DEBUG log of one restart on the dev build with the speaker off, from "bootstrapping" to "startup complete"? And is zone 16 part of a group, either a fixed group in Loxone Config or one you made in the app?

rudyberends avatar Nov 30 '26 09:11 rudyberends

Thanks! Here is the DEBUG log of that restart on 4.0.0-beta.25+dev-20261128174634 with zone 16 (Sonos S2, 192.168.178.49) powered off, from "bootstrapping" to "startup complete". IDs are redacted; repetitive per-zone lines, "sonos state update" lines and multi-line Sonos message dumps are condensed (marked in the log). I can send the complete raw log if you need it.

What stands out:

  • 09:26:42.091 the zone-16 state controller fails ("fetch failed", reconnect scheduled), zones registered, then spotify manager reloaded at 09:26:42.094.
  • After that there is no log output at all for exactly 180 s.
  • 09:29:42.258 Sonn tries to disconnect the zone-16 Sonos client, which was never created: Cannot read properties of undefined (reading 'disconnect').
  • Right after that, the websockets of all other (working) Sonos zones are disconnected and reconnected, and only then the HTTP gateway / Loxone servers start listening.

So it looks like a step after the Spotify manager reload waits on zone 16 with a 180 s timeout and, when it times out, restarts all Sonos state controllers before the listeners are started. All zones are discovered by fixed IP (controlUrl=undefined, "awaiting discovery").

Regarding groups: in Sonos each speaker is its own group (10 groups in the topology, zone 16 alone). I couldn't find a fixed group containing zone 16 in Loxone Config, and as far as I know it wasn't grouped in the app at that time either.

DEBUG log (restart with zone 16 off, condensed)
[2026-11-29T09:26:35.911Z][INFO][Server] [env=development loxoneEnabled=true] bootstrapping audio server
[2026-11-29T09:26:35.924Z][INFO][Output|Factory] [controlUrl=undefined host=192.168.178.49 zoneId=16] Sonos output registered
[2026-11-29T09:26:35.924Z][INFO][Output|Sonos] [host=192.168.178.49 zoneId=16] Sonos output awaiting discovery
   (same "registered" / "awaiting discovery" for zones 9-18)
[2026-11-29T09:26:35.928Z][INFO][Zones|StateControllers] [controller=sonos zoneId=16] state controller starting
   (same for zones 9-18)
[2026-11-29T09:26:35.956Z][DEBUG][Content|SpotifyManager] [accounts=3] spotify manager reloaded
[2026-11-29T09:26:35.965Z][INFO][Zones|Manager] [index=0 items=1 positionSec=0 zoneId=11] queue restored
[2026-11-29T09:26:35.966Z][INFO][Zones|Manager] [index=0 items=1 positionSec=0 zoneId=15] queue restored
[2026-11-29T09:26:35.967Z][INFO][Zones|Manager] [index=0 items=1 positionSec=0 zoneId=16] queue restored
[2026-11-29T09:26:36.031Z][INFO][Zones|StateController:Sonos] [generation=S2 host=192.168.178.106 zoneId=18] sonos state controller backend selected
[2026-11-29T09:26:36.039Z][INFO][Zones|StateController:Sonos] [generation=S2 host=192.168.178.39 zoneId=12] sonos state controller backend selected
[2026-11-29T09:26:36.041Z][INFO][Zones|StateController:Sonos] [generation=S2 host=192.168.178.38 zoneId=13] sonos state controller backend selected
[2026-11-29T09:26:36.042Z][INFO][Zones|StateController:Sonos] [generation=S2 host=192.168.178.126 zoneId=14] sonos state controller backend selected
[2026-11-29T09:26:36.050Z][INFO][Zones|StateController:Sonos] [generation=S2 host=192.168.178.41 zoneId=9] sonos state controller backend selected
[2026-11-29T09:26:36.052Z][INFO][Zones|StateController:Sonos] [generation=S2 host=192.168.178.42 zoneId=15] sonos state controller backend selected
[2026-11-29T09:26:36.055Z][INFO][Zones|StateController:Sonos] [generation=S2 host=192.168.178.134 zoneId=10] sonos state controller backend selected
[2026-11-29T09:26:36.061Z][INFO][Zones|StateController:Sonos] [generation=S2 host=192.168.178.37 zoneId=11] sonos state controller backend selected
[2026-11-29T09:26:36.235Z][INFO][Zones|StateController:Sonos] [generation=S2 host=192.168.178.40 zoneId=17] sonos state controller backend selected
[2026-11-29T09:26:36.292Z][INFO][Zones|StateController:Sonos] [host=192.168.178.39 zoneId=12 zoneName="Flur OG"] sonos state controller connected
[2026-11-29T09:26:36.298Z][INFO][Zones|StateController:Sonos] [host=192.168.178.38 zoneId=13 zoneName="Flur EG"] sonos state controller connected
[2026-11-29T09:26:36.299Z][INFO][Zones|StateController:Sonos] [host=192.168.178.126 zoneId=14 zoneName="Flur Keller"] sonos state controller connected
[2026-11-29T09:26:36.314Z][INFO][Zones|StateController:Sonos] [host=192.168.178.106 zoneId=18 zoneName=Garten] sonos state controller connected
[2026-11-29T09:26:36.398Z][INFO][Zones|StateController:Sonos] [host=192.168.178.134 zoneId=10 zoneName=Büro] sonos state controller connected
[2026-11-29T09:26:36.399Z][INFO][Zones|StateController:Sonos] [host=192.168.178.41 zoneId=9 zoneName=Bad] sonos state controller connected
[2026-11-29T09:26:36.404Z][INFO][Zones|StateController:Sonos] [host=192.168.178.37 zoneId=11 zoneName=Esszimmer] sonos state controller connected
[2026-11-29T09:26:36.408Z][INFO][Zones|StateController:Sonos] [host=192.168.178.42 zoneId=15 zoneName=Schlafzimmer] sonos state controller connected
[2026-11-29T09:26:36.728Z][INFO][Zones|StateController:Sonos] [host=192.168.178.40 zoneId=17 zoneName=Wohnzimmer] sonos state controller connected
[2026-11-29T09:26:37.813Z][DEBUG][Input|SoloistWs] [message="connect ECONNREFUSED 127.0.0.1:38555" zoneId=16] soloist control channel error
[2026-11-29T09:26:38.063Z][DEBUG][Input|SoloistWs] [port=38555 zoneId=16] soloist control channel open
   (soloists for zones 9-18 start one after another, all "control channel open" by 09:26:38.576)
[2026-11-29T09:26:39.019Z][INFO][Zones|StateController:Sonos] [generation=unknown host=192.168.178.49 zoneId=16] sonos state controller backend selected
[2026-11-29T09:26:42.091Z][WARN][Zones|StateController:Sonos] [host=192.168.178.49 message="fetch failed" zoneId=16] sonos state controller failed to start
[2026-11-29T09:26:42.091Z][INFO][Zones|StateController:Sonos] [delayMs=5000 host=192.168.178.49 zoneId=16] sonos reconnect scheduled
[2026-11-29T09:26:42.091Z][INFO][Zones|Manager] [count=10] zones registered
[2026-11-29T09:26:42.094Z][DEBUG][Content|SpotifyManager] [accounts=3] spotify manager reloaded
   ----- no log output at all for 180 s -----
[2026-11-29T09:29:42.258Z][DEBUG][Zones|StateController:Sonos] [message="Cannot read properties of undefined (reading 'disconnect')" zoneId=16] sonos client disconnect failed; closing its transport directly
[2026-11-29T09:29:42.275Z][WARN][Zones|StateController:Sonos] [host=192.168.178.40 zoneId=17] sonos websocket disconnected
[2026-11-29T09:29:42.275Z][INFO][Zones|StateController:Sonos] [delayMs=5000 host=192.168.178.40 zoneId=17] sonos reconnect scheduled
[2026-11-29T09:29:42.275Z][WARN][Zones|StateController:Sonos] [host=192.168.178.42 zoneId=15] sonos websocket disconnected
[2026-11-29T09:29:42.276Z][WARN][Zones|StateController:Sonos] [host=192.168.178.41 zoneId=9] sonos websocket disconnected
[2026-11-29T09:29:42.276Z][WARN][Zones|StateController:Sonos] [host=192.168.178.37 zoneId=11] sonos websocket disconnected
[2026-11-29T09:29:42.276Z][WARN][Zones|StateController:Sonos] [host=192.168.178.134 zoneId=10] sonos websocket disconnected
[2026-11-29T09:29:42.277Z][WARN][Zones|StateController:Sonos] [host=192.168.178.126 zoneId=14] sonos websocket disconnected
[2026-11-29T09:29:42.277Z][WARN][Zones|StateController:Sonos] [host=192.168.178.39 zoneId=12] sonos websocket disconnected
[2026-11-29T09:29:42.277Z][WARN][Zones|StateController:Sonos] [host=192.168.178.106 zoneId=18] sonos websocket disconnected
[2026-11-29T09:29:42.278Z][WARN][Zones|StateController:Sonos] [host=192.168.178.38 zoneId=13] sonos websocket disconnected
   (each followed by "sonos reconnect scheduled delayMs=5000")
[2026-11-29T09:29:42.537Z][INFO][Audio|LineInMetadata] [enabled=true enabledInputs=0 inputs=0] line-in metadata init
[2026-11-29T09:29:42.538Z][INFO][Output|SqueezeliteCore] [port=3483] SlimProto server started
[2026-11-29T09:29:42.546Z][INFO][Http] [host=0.0.0.0 port=7090] http gateway listening
[2026-11-29T09:29:42.549Z][INFO][Server] [serverId=<id>] sendspin server identity
[2026-11-29T09:29:42.598Z][INFO][LoxoneHttp] [name=appHttp port=7091 tls=dual] loxone server listening
[2026-11-29T09:29:42.599Z][INFO][LoxoneHttp] [name=msHttp port=7095 tls=dual] loxone server listening
[2026-11-29T09:29:42.599Z][INFO][LoxoneHttp] [ports="7091, 7095" tls=enabled] loxone servers ready
[2026-11-29T09:29:42.604Z][INFO][Server] [url=http://192.168.178.245/dev/sps/devicestartup/<uuid>] miniserver startup ping sent
[2026-11-29T09:29:42.604Z][INFO][Server] startup complete

logol01 avatar Nov 30 '26 11:11 logol01

Thanks, this log helps a lot. The striking part is that during those 180 s even zone 16's own reconnect timer (5 s) doesn't fire, and at 09:29:42 everything happens at once: that reconnect, and all other Sonos websockets dropping. That points to something holding up the whole process for those 3 minutes, not to a normal wait on the speaker. I haven't found what yet. Three things would help:

  1. The complete raw log of such a restart, nothing condensed.
  2. Your config.json with passwords and tokens removed, so I can rebuild your setup here.
  3. A CPU profile of one restart with the speaker off. Set NODE_OPTIONS=--cpu-prof on the container, restart with the speaker off, wait for "startup complete", then stop the container. A .cpuprofile file then appears in the container's working directory (/app). That shows exactly where the 3 minutes go.

rudyberends avatar Nov 30 '26 11:11 rudyberends

Found it with the CPU profile (restart today 12:41 UTC on the same dev build with zone 16 off, again exactly 180 s between "zones registered" and "startup complete"): 180.03 s of the 302 s profile are self time in a single synchronous call, process.report.getReport(), with this stack:

getReport (report:58)
 <- isLinuxMusl (binding.js:52)
 <- getPrebuildPath (binding.js:41)
 <- getBinding (binding.js:9)
 <- Database (database.js:8)
 <- init (localLibraryStore.js:21)

So the libc detection of the SQLite binding, used when the local library store is initialised, calls process.report.getReport(). The diagnostic report includes the network handles and resolves their endpoints, which apparently blocks while a connection attempt to the unreachable speaker (192.168.178.49) is pending. Since it is synchronous, the whole event loop is blocked, which is why even the zone-16 reconnect timer doesn't fire.

Possible fixes: initialise the library store before any outbound connections are opened, set process.report.excludeNetwork = true (or --report-exclude-network) before that call if the Node version supports it, or use a libc detection that doesn't go through getReport().

Also confirmed from this log: the Miniserver sends audio/cfg/groupopts = {"groups":[]}, so there are no fixed groups.

I'll attach the complete raw log of this restart (IDs, account name and the secure/peers token redacted, nothing else removed) and the .cpuprofile below.

logol01 avatar Nov 30 '26 12:11 logol01

Attachments for the comment above: complete raw log of the restart (30 Nov 12:41 UTC, zone 16 off; Spotify account name, IDs and the secure/peers token redacted, nothing else removed) and the CPU profile.

sonn_465_restart_bereinigt.log

CPU.20261130.134140.1.0.001.cpuprofile

logol01 avatar Nov 30 '26 12:11 logol01

Nice find, that was it. The SQLite binding calls process.report.getReport() once to check the C library, and that report looks up every open socket. With the connection to the speaker that is off still pending, that one call blocked everything. sonn now sets process.report.excludeNetwork before it starts (7ce6a7a on dev). Can you try a restart with zone 16 off on the next dev build?

rudyberends avatar Nov 30 '26 14:11 rudyberends

Tested on 4.0.0-beta.25+dev-20261130144304 (includes 7ce6a7a): restart with zone 16 powered off, bootstrapping → startup complete in 6.5 s (was exactly 180 s before). Zone 16 keeps retrying in the background with backoff and connects as soon as the speaker is back. Fixed from my side, thanks a lot!

logol01 avatar Dec 01 '26 00:12 logol01