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

Package:
libpulse0
Source:
libpulse0
Description:
PulseAudio client libraries
Submitter:
Chris Vogel
Date:
2023-12-06 08:57:03 UTC
Severity:
normal
Tags:
#1056383#5
Date:
2023-11-22 05:10:50 UTC
From:
To:
(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@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
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);
---
```

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.

#1056383#12
Date:
2023-12-04 07:47:01 UTC
From:
To:
I've been running the patched version of pulseaudio for a few days now.

Open memfd for the software I'm using are staying a lot lower except for gnome-shell:

`lsof | grep 'memfd:pulseaudio (deleted)' | cut -c1-16 | sort | uniq -c | sort -n`

gives me

```
       3 callaudio 47850
      10 gsd-media 47461
      25 dino-im   51472
      27 nheko     49733
     123 firefox-b 47974
     167 thunderbi 34794
     188 thunderbi 50508
     208 firefox-b 48541
     500 firefox-b 48996
    1681 gnome-she 47208
```

The numbers above accumulated during 7 days uptime. Applications have not been restarted. The open memfds for gnome-shell look like this:

`gnome-she 47208                           user   81u      REG                0,1    67108864     180957 /memfd:pulseaudio (deleted)`

#1056383#17
Date:
2023-12-06 08:52:18 UTC
From:
To:
My gnome-session has been running from Nov 27 until today Dec 6.

Now pipewire-pulse stopped working again:

someuser@pureos:~$ paplay /usr/share/sounds/alsa/Front_Center.wav
Connection failure: Connection terminated
→ Can't play sound via pulseaudio
someuser@pureos:~$ pw-play /usr/share/sounds/alsa/Front_Center.wav
→ Sound via pipewire still works

At the start
`lsof | grep 'memfd:pulseaudio (deleted)' | cut -c1-16 | sort | uniq -c | sort -n`
returned

```
       3 callaudio 47850
       4 gsd-media 47461
      23 dino-im   51472
      27 nheko     49733
      96 firefox-b 48541
     123 gnome-she 47208
     310 firefox-b 48996
```

now it shows:

```
       3 callaudio 47850
      10 gsd-media 47461
      25 dino-im   51472
      27 nheko     49733
     124 firefox-b 47974
     178 thunderbi 50508
     230 firefox-b 48541
     548 firefox-b 48996
    2173 gnome-she 47208
```

I became aware of the problem, because after waking up from suspend I couldn't start playing a radio station in shortwave anymore which showed me instead of the play button a red 'no passing' sign.

`journalctl -S -4d -t pipewire-pulse | cat` shows

```
Dez 03 12:05:24 PureBlackSoul pipewire-pulse[35741]: mod.rt: Can't find org.freedesktop.portal.Desktop. Is xdg-desktop-portal running?
Dez 03 12:05:24 PureBlackSoul pipewire-pulse[35741]: mod.rt: found session bus but no portal
Dez 03 13:13:55 PureBlackSoul pipewire-pulse[16730]: mod.rt: Can't find org.freedesktop.portal.Desktop. Is xdg-desktop-portal running?
Dez 03 13:13:55 PureBlackSoul pipewire-pulse[16730]: mod.rt: found session bus but no portal
Dez 04 08:05:00 PureBlackSoul pipewire-pulse[5629]: mod.protocol-pulse: 77: sink not ready: sample:0 map:0 volume:0
Dez 04 08:05:00 PureBlackSoul pipewire-pulse[5629]: mod.protocol-pulse: 77: source not ready: sample:0 map:0 volume:0
Dez 04 08:05:00 PureBlackSoul pipewire-pulse[5629]: mod.protocol-pulse: 77: sink not ready: sample:0 map:0 volume:0
Dez 04 08:05:00 PureBlackSoul pipewire-pulse[5629]: mod.protocol-pulse: 77: source not ready: sample:0 map:0 volume:0
Dez 04 08:05:00 PureBlackSoul pipewire-pulse[5629]: mod.protocol-pulse: 77: sink not ready: sample:0 map:0 volume:0
Dez 04 08:05:00 PureBlackSoul pipewire-pulse[5629]: mod.protocol-pulse: 77: source not ready: sample:0 map:0 volume:0
Dez 04 08:05:00 PureBlackSoul pipewire-pulse[5629]: mod.protocol-pulse: 77: sink not ready: sample:0 map:0 volume:0
Dez 04 08:05:00 PureBlackSoul pipewire-pulse[5629]: mod.protocol-pulse: 77: source not ready: sample:0 map:0 volume:0
Dez 04 08:05:00 PureBlackSoul pipewire-pulse[5629]: mod.protocol-pulse: 77: sink not ready: sample:0 map:0 volume:0
Dez 04 08:05:00 PureBlackSoul pipewire-pulse[5629]: mod.protocol-pulse: 77: source not ready: sample:0 map:0 volume:0
Dez 04 08:05:03 PureBlackSoul pipewire-pulse[64370]: mod.rt: Can't find org.freedesktop.portal.Desktop. Is xdg-desktop-portal running?
Dez 04 08:05:03 PureBlackSoul pipewire-pulse[64370]: mod.rt: found session bus but no portal
Dez 05 14:47:45 PureBlackSoul pipewire-pulse[37533]: mod.rt: Can't find org.freedesktop.portal.Desktop. Is xdg-desktop-portal running?
Dez 05 14:47:45 PureBlackSoul pipewire-pulse[37533]: mod.rt: found session bus but no portal
Dez 05 19:06:36 PureBlackSoul pipewire-pulse[5629]: mod.protocol-pulse: server 0x5589b3a6d7e0: failed to create client: Verbindungsaufbau abgelehnt
Dez 05 19:06:36 PureBlackSoul pipewire-pulse[5629]: mod.protocol-pulse: server 0x5589b3a6d7e0: failed to create client: Verbindungsaufbau abgelehnt
Dez 05 19:06:56 PureBlackSoul pipewire-pulse[5629]: mod.protocol-pulse: server 0x5589b3a6d7e0: failed to create client: Verbindungsaufbau abgelehnt
Dez 05 19:06:56 PureBlackSoul pipewire-pulse[5629]: mod.protocol-pulse: server 0x5589b3a6d7e0: failed to create client: Verbindungsaufbau abgelehnt
Dez 05 19:06:59 PureBlackSoul pipewire-pulse[30822]: mod.rt: Can't find org.freedesktop.portal.Desktop. Is xdg-desktop-portal running?
Dez 05 19:06:59 PureBlackSoul pipewire-pulse[30822]: mod.rt: found session bus but no portal
Dez 05 19:07:09 PureBlackSoul pipewire-pulse[5629]: mod.protocol-pulse: server 0x5589b3a6d7e0: failed to create client: Verbindungsaufbau abgelehnt
Dez 05 19:07:09 PureBlackSoul pipewire-pulse[5629]: mod.protocol-pulse: server 0x5589b3a6d7e0: failed to create client: Verbindungsaufbau abgelehnt
Dez 05 19:07:10 PureBlackSoul pipewire-pulse[5629]: mod.protocol-pulse: server 0x5589b3a6d7e0: failed to create client: Verbindungsaufbau abgelehnt
Dez 05 19:07:10 PureBlackSoul pipewire-pulse[5629]: mod.protocol-pulse: server 0x5589b3a6d7e0: failed to create client: Verbindungsaufbau abgelehnt
Dez 05 19:07:10 PureBlackSoul pipewire-pulse[5629]: mod.protocol-pulse: server 0x5589b3a6d7e0: failed to create client: Verbindungsaufbau abgelehnt
Dez 05 19:21:57 PureBlackSoul pipewire-pulse[5629]: mod.protocol-pulse: server 0x5589b3a6d7e0: failed to create client: Verbindungsaufbau abgelehnt
Dez 05 19:21:58 PureBlackSoul pipewire-pulse[5629]: mod.protocol-pulse: server 0x5589b3a6d7e0: failed to create client: Verbindungsaufbau abgelehnt
Dez 06 08:20:51 PureBlackSoul pipewire-pulse[5629]: mod.protocol-pulse: server 0x5589b3a6d7e0: failed to create client: Verbindungsaufbau abgelehnt
Dez 06 08:20:51 PureBlackSoul pipewire-pulse[5629]: mod.protocol-pulse: server 0x5589b3a6d7e0: failed to create client: Verbindungsaufbau abgelehnt
Dez 06 08:21:12 PureBlackSoul pipewire-pulse[5629]: mod.protocol-pulse: server 0x5589b3a6d7e0: failed to create client: Verbindungsaufbau abgelehnt
Dez 06 08:21:19 PureBlackSoul pipewire-pulse[5629]: mod.protocol-pulse: server 0x5589b3a6d7e0: failed to create client: Verbindungsaufbau abgelehnt
Dez 06 08:21:24 PureBlackSoul pipewire-pulse[5629]: mod.protocol-pulse: server 0x5589b3a6d7e0: failed to create client: Verbindungsaufbau abgelehnt
Dez 06 08:21:29 PureBlackSoul pipewire-pulse[5629]: mod.protocol-pulse: server 0x5589b3a6d7e0: failed to create client: Verbindungsaufbau abgelehnt
Dez 06 08:21:34 PureBlackSoul pipewire-pulse[5629]: mod.protocol-pulse: server 0x5589b3a6d7e0: failed to create client: Verbindungsaufbau abgelehnt
Dez 06 08:21:39 PureBlackSoul pipewire-pulse[5629]: mod.protocol-pulse: server 0x5589b3a6d7e0: failed to create client: Verbindungsaufbau abgelehnt
Dez 06 08:21:44 PureBlackSoul pipewire-pulse[5629]: mod.protocol-pulse: server 0x5589b3a6d7e0: failed to create client: Verbindungsaufbau abgelehnt
Dez 06 08:21:49 PureBlackSoul pipewire-pulse[5629]: mod.protocol-pulse: server 0x5589b3a6d7e0: failed to create client: Verbindungsaufbau abgelehnt
Dez 06 08:21:54 PureBlackSoul pipewire-pulse[5629]: mod.protocol-pulse: server 0x5589b3a6d7e0: failed to create client: Verbindungsaufbau abgelehnt
Dez 06 08:21:59 PureBlackSoul pipewire-pulse[5629]: mod.protocol-pulse: server 0x5589b3a6d7e0: failed to create client: Verbindungsaufbau abgelehnt
Dez 06 08:23:02 PureBlackSoul pipewire-pulse[5629]: mod.protocol-pulse: server 0x5589b3a6d7e0: failed to create client: Verbindungsaufbau abgelehnt
Dez 06 08:23:02 PureBlackSoul pipewire-pulse[5629]: mod.protocol-pulse: server 0x5589b3a6d7e0: failed to create client: Verbindungsaufbau abgelehnt
Dez 06 08:23:06 PureBlackSoul pipewire-pulse[33485]: mod.rt: Can't find org.freedesktop.portal.Desktop. Is xdg-desktop-portal running?
Dez 06 08:23:06 PureBlackSoul pipewire-pulse[33485]: mod.rt: found session bus but no portal
Dez 06 08:23:55 PureBlackSoul pipewire-pulse[5629]: mod.protocol-pulse: server 0x5589b3a6d7e0: failed to create client: Verbindungsaufbau abgelehnt
Dez 06 08:23:55 PureBlackSoul pipewire-pulse[5629]: mod.protocol-pulse: server 0x5589b3a6d7e0: failed to create client: Verbindungsaufbau abgelehnt
Dez 06 08:23:56 PureBlackSoul pipewire-pulse[5629]: mod.protocol-pulse: server 0x5589b3a6d7e0: failed to create client: Verbindungsaufbau abgelehnt
Dez 06 08:23:56 PureBlackSoul pipewire-pulse[5629]: mod.protocol-pulse: server 0x5589b3a6d7e0: failed to create client: Verbindungsaufbau abgelehnt
Dez 06 08:23:56 PureBlackSoul pipewire-pulse[5629]: mod.protocol-pulse: server 0x5589b3a6d7e0: failed to create client: Verbindungsaufbau abgelehnt
Dez 06 08:38:27 PureBlackSoul pipewire-pulse[5629]: mod.protocol-pulse: server 0x5589b3a6d7e0: failed to create client: Verbindungsaufbau abgelehnt
Dez 06 08:38:41 PureBlackSoul pipewire-pulse[5629]: mod.protocol-pulse: server 0x5589b3a6d7e0: failed to create client: Verbindungsaufbau abgelehnt
Dez 06 09:43:02 PureBlackSoul pipewire-pulse[5629]: mod.protocol-pulse: server 0x5589b3a6d7e0: failed to create client: Verbindungsaufbau abgelehnt
Dez 06 09:43:41 PureBlackSoul pipewire-pulse[5629]: mod.protocol-pulse: server 0x5589b3a6d7e0: failed to create client: Verbindungsaufbau abgelehnt
Dez 06 09:44:10 PureBlackSoul pipewire-pulse[5629]: mod.protocol-pulse: server 0x5589b3a6d7e0: failed to create client: Verbindungsaufbau abgelehnt
```