[Volumio 4 + RPi5] DSD/DoP playback crashes Volumio with assert.ok(self.idling) - MPD double restart (Fixed)

http://logs.volumio.org/volumio/ehs9uZ6.html

Body:
System Information

  • Hardware: Raspberry Pi 5
  • Volumio Version: 4.119
  • DAC 1: Custom STM32 H750 USB Audio (UAC2, VID:PID 1209:2028)
  • DAC 2: XMOS-based USB DAC
  • Connection: USB

Problem

DSD/DoP playback is broken on Volumio 4 on Raspberry Pi 5.
PCM playback works normally.

The issue is reproducible with two completely different USB DACs:

  • custom STM32 UAC2 DAC
  • XMOS-based DAC

This strongly suggests the problem is not DAC firmware or USB hardware specific.

Observed behavior

When a DSD file is selected in Volumio:

  • playback spinner appears
  • MPD is restarted
  • playback fails
  • Volumio player recovers/restarts

Exact error seen in Volumio log:

error: MPD error: The expression evaluated to a falsy value:
assert.ok(self.idling)
Location: /volumio/app/plugins/music_service/mpd/lib/mpd.js:93

What works

  • PCM playback in Volumio
  • direct ALSA playback to hw: device
  • direct MPD playback via mpc
  • DSD/DoP playback outside Volumio control path

What fails

  • DSD/DoP playback only when initiated through Volumio UI / Volumio MPD control flow

Root cause analysis
assert.ok(self.idling)
Location: /volumio/app/plugins/music_service/mpd/lib/mpd.js:93
Root cause analysis (via SSH debugging):
When a DSD file is played, the following sequence happens:

MPD starts playing DSD → triggers ALSA format change
This causes alsa.outputdevice sharedVar to be set in alsa_controller
outputDeviceCallback fires in mpd/index.js
This triggers restartMpd() — while MPD is already restarting from onStart
Double MPD restart → race condition → self.idling = false when sendCommand is called
assert.ok(self.idling) throws → Volumio crashes and restarts

Key finding:
sudo journalctl -u volumio | grep “restart mpd”

Shows TWO consecutive “systemctl restart mpd.service” calls

within milliseconds of each other on every DSD play attempt

Additional findings:

aplay directly to hw:DAC works perfectly with DSD/DoP
MPD via mpc directly also works
Only fails when Volumio controls MPD
Issue confirmed on two different USB DACs (UAC2 STM32, XMOS)
Was working on Volumio 3 + RPi4

Affected files:

/volumio/app/plugins/music_service/mpd/lib/mpd.js line 93 — assert.ok(self.idling) has no guard against race condition
/volumio/app/plugins/music_service/mpd/index.js line 781 — outputDeviceCallback triggered by DSD format switch

Suggested fix:
Replace assert.ok(self.idling) in mpd.js:sendCommand with a proper guard, and add debounce to outputDeviceCallback to prevent double MPD restart.
Via SSH/debugging, the sequence appears to be:

  1. DSD playback starts and triggers an ALSA format/output change
  2. alsa.outputdevice sharedVar is updated in alsa_controller
  3. outputDeviceCallback fires in mpd/index.js
  4. This triggers restartMpd()
  5. But MPD is already in restart/start transition
  6. A second MPD restart is issued almost immediately
  7. This creates a race condition where self.idling is false when sendCommand() is called
  8. assert.ok(self.idling) throws and Volumio playback crashes/restarts

Evidence

Running:

journalctl -u volumio | grep “restart mpd”

shows two consecutive systemctl restart mpd.service calls within milliseconds during every DSD playback attempt.

Why this seems like a Volumio bug

  • reproduced on two different DACs
  • direct MPD playback works
  • direct ALSA playback works
  • only Volumio-controlled playback fails
  • worked previously on Volumio 3 + Raspberry Pi 4

Affected files

  • /volumio/app/plugins/music_service/mpd/lib/mpd.js line 93
    assert.ok(self.idling) has no protection against this race
  • /volumio/app/plugins/music_service/mpd/index.js around outputDeviceCallback / restart path

Suggested fix

  • Replace assert.ok(self.idling) in sendCommand() with a safe guard / error handling path
  • Add debounce or reentrancy protection around outputDeviceCallback
  • Prevent duplicate restartMpd() calls during output format/device transitions

Note: DACs (volumio 3 and rpi4) can play DSD files on the system.

FIXED

ROOT CAUSE FOUND:

The actual bug is NOT DSD-specific. It is caused by a .cue file in the music library.

When Volumio queues a folder containing a .cue file, it processes the file twice, causing:

Error: Unable to resolve or reject the same promise twice
at /volumio/app/plugins/music_service/mpd/index.js:2569

This crashes Volumio → restart → double MPD restart → assert.ok(self.idling) → DSD playback fails.

Fix: Remove or rename the .cue file. DSD playback works perfectly.

Affected file: /volumio/app/plugins/music_service/mpd/index.js line 2569