Bug#1056383: pipewire-pulse stops working after a few days uptime

Chris Vogel chris at z9.de
Wed Nov 22 05:10:50 GMT 2023


Package: libpulse0
Version: 16.1+dfsg1-2+b1
Severity: normal
Tags: patch fixed-upstream

(This will appear to be a pipewire bug, but in the end it looks like the problem is pulseaudio not closing file handles. I therefor file this bug to libpulse0 which I believe (no developer here) is used by the clients using pulseaudio.)

After my notebook is running quite a few days (suspended during nights, used during days) having running multiple instances of firefox and thunderbird and listening to music using the shortwave flatpak the sound stops working.

Shortwave shows a red 'prohibited' sign where usually would be the play button, pa-play can't play any sound anymore, pactl throws an error:

```
someuser at pureos:~$ pactl list
Connection failure: Connection terminated
```

Using `pw-play` or `aplay` I can still play audio files.

When looking at the open files I found that there are a few thousand memfd filehandles open:

```
# lsof | grep pulse | grep -v '/lib/\|/share/' | cut -c1-10,107- | sort | uniq -c | sort -n
lsof: WARNING: can't stat() fuse.gvfsd-fuse file system /run/user/1000/gvfs
       Output information may be incomplete.
lsof: WARNING: can't stat() fuse.portal file system /run/user/1000/doc
       Output information may be incomplete.
       1 systemd   /run/user/1000/pulse/native type=STREAM (LISTEN)
       2 pipewire- /run/user/1000/pulse/native type=STREAM (LISTEN)
       3 callaudio /memfd:pulseaudio
       3 callaudio /memfd:pulseaudio (deleted)
       7 firefox   /memfd:pulseaudio (deleted)
      10 gsd-media /memfd:pulseaudio
      10 gsd-media /memfd:pulseaudio (deleted)
      27 nheko     /memfd:pulseaudio
      27 nheko     /memfd:pulseaudio (deleted)
     128 pipewire- /run/user/1000/pulse/native type=STREAM (CONNECTED)
     176 thunderbi /memfd:pulseaudio
     184 flatpak-s /memfd:pulseaudio (deleted)
     288 virt-mana /memfd:pulseaudio (deleted)
     874 firefox-b /memfd:pulseaudio
     940 NitrokeyA /memfd:pulseaudio (deleted)
    2274 firefox-b /memfd:pulseaudio (deleted)
    2378 gnome-she /memfd:pulseaudio
    2378 gnome-she /memfd:pulseaudio (deleted)
    9680 thunderbi /memfd:pulseaudio (deleted)
```

Sometimes it helps to stop thunderbird and firefox, restart pipewire-pulse.socket pipewire-pulse and then try again playing sound using e.g. `paplay`.

Other times I have to log out and in again to get rid of the rest of the open files.

I configured pipewire-pulse to not offer unix:native for connections, but instead only tcp and made programs use that connection by configuring pulseaudios client.conf to disable shm and memfd and set a default-server.

This stopped the problem from occuring and no memfd entries got accumulated, but let to other problems (volume control, general integration into gnome).

I found the following issues that might be related to the problem:

https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/issues/1394
https://gitlab.freedesktop.org/pipewire/pipewire/-/issues/3406

The changes following the pulseaudio issue do not seem to be integrated into the bookworm package, yet.

To test whether they might help I compiled built the packages I have installed for pulseaudio (libpulse-mainloop-glib0:amd64, libpulse0:amd64, libpulsedsp:amd64, pulseaudio, pulseaudio-utils) with the following patch applied to find out whether this would help:

```
diff -r pulseaudio-orig/pulseaudio-16.1+dfsg1/src/pulsecore/memfd-wrappers.h pulseaudio-patched/pulseaudio-16.1+dfsg1/src/pulsecore/memfd-wrappers.h
68a69,72
> #ifndef MFD_NOEXEC_SEAL
> #define MFD_NOEXEC_SEAL   0x0008U
> #endif
> 
diff -r pulseaudio-orig/pulseaudio-16.1+dfsg1/src/pulsecore/shm.c pulseaudio-patched/pulseaudio-16.1+dfsg1/src/pulsecore/shm.c
167c167
<         fd = memfd_create("pulseaudio", MFD_ALLOW_SEALING);
---
>         fd = memfd_create("pulseaudio", MFD_ALLOW_SEALING|MFD_CLOEXEC);
```

After half a day of use I found that at least the number of open memfds increases and once in while decreases again. I'll have to wait for a longer period of time to find out whether the situation really improved.



More information about the pkg-pulseaudio-devel mailing list