Every couple of days my audio and audio applications would stop working. Through some trial and error I found that restarting pipewire-pulse would temporarily work around the issue– music would play again, my volume keys would start working – for another couple of days..

systemctl restart --user pipewire-pulse

I eventually tired of this work-around and decided to look into it further. The messages coming from the pipewire-pulse server looked like this, one for each failed attempt to do something, like volume-up/down.

 mod.protocol-pulse: server 0x5654295d2940: failed to create client: Connection refused
 mod.protocol-pulse: server 0x5654295d2940: failed to create client: Connection refused
 mod.protocol-pulse: server 0x5654295d2940: failed to create client: Connection refused
 mod.protocol-pulse: server 0x5654295d2940: failed to create client: Connection refused
 mod.protocol-pulse: server 0x5654295d2940: failed to create client: Connection refused
 mod.protocol-pulse: server 0x5654295d2940: failed to create client: Connection refused

I grepped through the pipewire-pulse code and found that this error message is emitted when the number of pipewire-pulse clients reaches its limit (by default 64). The developers on the pipewire matrix channel told me I could list all the pipewire-pulse clients by running pw-cli ls. This showed 48 pipewire-pulse clients created by Spotify! (It should only need one to do its thing.) Since spotify is closed-source, I wasn’t able to fix the problem at its root. Instead I wrote a small program to remove all but the oldest pipewire-pulse clients. I run that program via a systemd user service every 30 minutes and just like that, no more audio problems. This program only works if you’re using pipewire. If you are still using pulse, you can use the script in the spotify issue below.

This issue was reported to spotify many years ago, but it’s likely a linux only issue and likely only affects those of us on desktops that leave spotify open all the time. It seems to occur more frequently on my desktop when I use spotify on another platform.

Coding around a bug in a closed-source program is very unsatisfying. Unfortunately the eye-candy of Spotify has made it hard for me to accept other spotify clients and I find it too convenient to ditch it completely.