Skip to content

fix(viewer): clear stale PulseAudio pid file so audio survives reboot#3113

Merged
vpetersson merged 1 commit into
masterfrom
fix/pulseaudio-stale-pidfile-3112
Jul 5, 2026
Merged

fix(viewer): clear stale PulseAudio pid file so audio survives reboot#3113
vpetersson merged 1 commit into
masterfrom
fix/pulseaudio-stale-pidfile-3112

Conversation

@vpetersson

Copy link
Copy Markdown
Contributor

Issues Fixed

Fixes #3112 (follow-up to #3001).

Description

On Qt 6 boards (Pi 4/5, x86), HDMI audio works on a fresh install but dies after a reboot — intermittently. The viewer logs the generic E: [pulseaudio] main.c: Daemon startup failed. and falls into the "video will play without audio" branch; with no PulseAudio server, QtMultimedia has no audio backend and video plays silent.

Root cause (captured on real hardware via --log-target=file:): the hidden reason is E: [pulseaudio] pid.c: Daemon already running. — a stale ${XDG_RUNTIME_DIR}/pulse/pid. In Docker, /run is not a per-boot tmpfs like on bare metal — it lives in the container's writable layer — so the pid file survives a container restart or a device reboot (the restart: always viewer is restarted, reusing the layer). --daemonize=yes self-re-execs the daemon; the pre-exec process overwrites the stale pid file with its own PID, then the re-exec'd process re-runs pa_pid_file_create() and racily reads that PID as a live pulseaudio (itself) and aborts. The race is why the failure is intermittent.

Fix: remove the stale pid file before starting the daemon. The stale socket is already handled by module-native-protocol-unix's own stale-socket unlink, so only the pid file needs clearing.

Validation (A/B via a docker restart loop that reproduces the exact stale-/run condition):

Board Baseline (no fix) With fix
Pi 4 13/14 DOWN (+ 5/5 host reboots failed) 18/18 UP
Pi 5 12/12 DOWN 12/12 UP
x86 12/12 DOWN 12/12 UP

Checklist

  • I have performed a self-review of my own code.
  • New and existing unit tests pass locally and on CI with my changes. (no unit coverage for this shell path)
  • I have done an end-to-end test for Raspberry Pi devices. (real Pi 4 and Pi 5, full container stack)
  • I have tested my changes for x86 devices. (real x86 testbed)
  • I added a documentation for the changes I have made (when necessary). (n/a)

🤖 Generated with Claude Code

- rm the pid file before the --daemonize start in start_pulseaudio()
- XDG_RUNTIME_DIR is a persistent container path (not a per-boot
  tmpfs), so a SIGKILLed daemon's pid file survives a restart/reboot
  and trips a self-exec race ("Daemon already running"), leaving
  Qt 6 video silent (issue #3112)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@vpetersson vpetersson requested a review from a team as a code owner July 5, 2026 07:00
@vpetersson vpetersson self-assigned this Jul 5, 2026
@vpetersson vpetersson requested a review from Copilot July 5, 2026 07:00

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot wasn't able to review any files in this pull request.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@sonarqubecloud

sonarqubecloud Bot commented Jul 5, 2026

Copy link
Copy Markdown

@vpetersson vpetersson merged commit 6089f01 into master Jul 5, 2026
7 checks passed
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.

HDMI Audio on RPI - ref issue #3001 - after reboot still no audio on TV

2 participants