Bug 93109 - Race condition involving module-x11-bell and socket activation
Summary: Race condition involving module-x11-bell and socket activation
Status: RESOLVED FIXED
Alias: None
Product: PulseAudio
Classification: Unclassified
Component: modules (show other bugs)
Version: unspecified
Hardware: x86-64 (AMD64) Linux (All)
: medium normal
Assignee: pulseaudio-bugs
QA Contact: pulseaudio-bugs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-11-25 22:12 UTC by Eric Toombs
Modified: 2016-02-09 12:49 UTC (History)
3 users (show)

See Also:
i915 platform:
i915 features:


Attachments
startup log with -vvvvv (145.79 KB, text/plain)
2015-11-25 22:37 UTC, Eric Toombs
Details
the systemd log of events leading up to the pactl module load failure. (10.25 KB, text/plain)
2015-11-26 20:19 UTC, Eric Toombs
Details

Description Eric Toombs 2015-11-25 22:12:56 UTC
To start with, this bug only happens when I load module-x11-bell.

I'm starting pulseaudio immediately so that it can handle X11 bell events immediately. When socket activation is on, though, pulseaudio fails to start. These are the first few error messages:

Nov 25 10:54:28 lazarus slim[433]: E: [pulseaudio] socket-server.c: bind(): Address already in use
Nov 25 10:54:28 lazarus slim[433]: E: [pulseaudio] module.c: Failed to load module "module-native-protocol-unix" (argument: ""): initialization failed.
Nov 25 10:54:28 lazarus slim[433]: E: [pulseaudio] main.c: Module load failed.
Nov 25 10:54:28 lazarus systemd[471]: Starting Sound Service...
Nov 25 10:54:28 lazarus slim[433]: E: [pulseaudio] main.c: Failed to initialize daemon.

This happens with slim and with startx. Delaying pulseaudio's start by about 2 seconds resolves the race condition for both. Disabling socket activation also resolves the race condition:

mkdir -p ~/.config/systemd/user
systemctl --user mask pulseaudio.socket

I'll come back with the -vvvvv output.
Comment 1 Eric Toombs 2015-11-25 22:37:41 UTC
Created attachment 120123 [details]
startup log with -vvvvv
Comment 2 Tanu Kaskinen 2015-11-26 00:18:23 UTC
(In reply to Eric Toombs from comment #0)
> I'm starting pulseaudio immediately so that it can handle X11 bell events
> immediately.

What does this mean? How do you start pulseaudio?
Comment 3 Eric Toombs 2015-11-26 01:10:05 UTC
(In reply to Tanu Kaskinen from comment #2)
> (In reply to Eric Toombs from comment #0)
> > I'm starting pulseaudio immediately so that it can handle X11 bell events
> > immediately.
> 
> What does this mean? How do you start pulseaudio?

Oh, I meant I put
pulseaudio &
in my .xinitrc. The same thing also happens when I start pulseaudio from the
Comment 4 Eric Toombs 2015-11-26 01:12:23 UTC
Sorry, I accidentally posted before finishing the sentence. The same thing also happens when I start pulseaudio from the "Application Autostart" tab of XFCE's "Session and Startup" application.
Comment 5 Tanu Kaskinen 2015-11-26 18:52:29 UTC
If pulseaudio is managed by systemd, others shouldn't try to start it.

If you need to load module-x11-bell automatically when the X session starts, it should be sufficient to just load the module with pactl. The socket activation should ensure that pactl will be able talk to the server even if it's not running.
Comment 6 Eric Toombs 2015-11-26 20:18:02 UTC
(In reply to Tanu Kaskinen from comment #5)
> If pulseaudio is managed by systemd, others shouldn't try to start it.
> 
> If you need to load module-x11-bell automatically when the X session starts,
> it should be sufficient to just load the module with pactl. The socket
> activation should ensure that pactl will be able talk to the server even if
> it's not running.

I just tried that. I put this line

pactl load-module module-x11-bell sample=x11-bell

in my .xinitrc. It didn't work. The error messages about the socket are gone now, though. Now, the first error is this:

Nov 26 15:07:27 lazarus pulseaudio[544]: E: [pulseaudio] x11wrap.c: XOpenDisplay() failed
Nov 26 15:07:27 lazarus pulseaudio[544]: E: [pulseaudio] module.c: Failed to load module "module-x11-bell" (argument: "sample=x11-bell"): initialization failed.
Nov 26 15:07:27 lazarus slim[438]: Failure: Module initialization failed

I'm attaching the rest of the startup log.
Comment 7 Eric Toombs 2015-11-26 20:19:38 UTC
Created attachment 120153 [details]
the systemd log of events leading up to the pactl module load failure.
Comment 8 Tanu Kaskinen 2015-11-27 02:51:08 UTC
So XOpenDisplay() failed. That must be because the DISPLAY environment variable is not set in the context of systemd, and since pulseaudio is started by systemd, pulseaudio will inherit the environment variables from systemd.

I think there's some way to "upload" environment variables to systemd, but in this case you could also pass the "display" argument to module-x11-bell.
Comment 9 Janus Troelsen 2015-12-12 11:16:20 UTC
I am getting the same error, I am running Ubuntu and simply doing

xset b 100
pactl load-module module-x11-bell display=:0.0 sample=bell.ogg
pactl upload-sample /usr/share/sounds/ubuntu/stereo/bell.ogg bell.ogg

In my .xprofile. The server is running (I confirmed that using "pidof pulseaudio"). When I retry the second command, it always fails. The third always succeeds.
Comment 10 Tanu Kaskinen 2015-12-12 15:56:31 UTC
(In reply to Janus Troelsen from comment #9)
> I am getting the same error, I am running Ubuntu and simply doing

Which error? "bind(): Address already in use" or "XOpenDisplay() failed"?

Does Ubuntu start pulseaudio via systemd's socket activation or the old autospawn mechanism?
Comment 11 Rex Dieter 2015-12-13 14:43:41 UTC
Regarding comment #8, I think what you're looking for is:
dbus-update-activation-environment --systemd --all
Comment 12 Janus Troelsen 2015-12-14 11:32:37 UTC
Regarding comment #10: The error I was talking about is "Failure: Module initialization failed". I don't know how PulseAudio is started.
Comment 13 Tanu Kaskinen 2015-12-14 17:46:58 UTC
"Failure: Module initialization failed" can happen for many reasons. Let's not debug it here, since there doesn't seem to be any real connection to the original bug report.

You can either send a help request to the mailing list, or if you think it really is a bug in pulseaudio rather than just misconfiguration on your part, file a new bug report.
Comment 14 Tanu Kaskinen 2015-12-14 18:54:00 UTC
Sorry, my previous message wasn't really appropriate. I misremembered what had been said before.

So you get "Failure: Module initialization failed" when you try to load module-x11-bell with pactl. Does the "XOpenDisplay() failed" error appear in /var/log/syslog?

Are you sure that :0.0 is the right display string? I'm on Debian, and I have just :0 in $DISPLAY.
Comment 15 Eric Toombs 2016-01-11 05:14:44 UTC
You were right, Tanu. The error is due to the fact that pulseaudio didn't know which display to use. The following two lines in .xinitrc work fine:

pactl upload-sample /usr/share/sounds/freedesktop/stereo/bell.oga x11-bell
pactl load-module module-x11-bell sample=x11-bell display=:0.0

It is pretty clear that the method of having the following lines

### Load something into the sample cache
load-sample-lazy x11-bell /usr/share/sounds/freedesktop/stereo/bell.oga
### Load X11 bell module
load-module module-x11-bell sample=x11-bell

uncommented in /etc/pulse/default.pa was supposed to work, since those lines are provided by pulseaudio. Either pulseaudio should be modified so that uncommenting those lines does work, or else those lines should be changed or removed. Adding display=:0.0 to the arguments of module-x11-bell would work for the vast majority of cases.
Comment 16 Tanu Kaskinen 2016-02-06 13:38:48 UTC
(In reply to Eric Toombs from comment #15)
> It is pretty clear that the method of having the following lines
> 
> ### Load something into the sample cache
> load-sample-lazy x11-bell /usr/share/sounds/freedesktop/stereo/bell.oga
> ### Load X11 bell module
> load-module module-x11-bell sample=x11-bell
> 
> uncommented in /etc/pulse/default.pa was supposed to work, since those lines
> are provided by pulseaudio. Either pulseaudio should be modified so that
> uncommenting those lines does work, or else those lines should be changed or
> removed. Adding display=:0.0 to the arguments of module-x11-bell would work
> for the vast majority of cases.

It's not possible to put any X11 examples to default.pa that would reliably work, therefore I prefer removing the examples. Patch submitted: https://patchwork.freedesktop.org/patch/72830/
Comment 17 Tanu Kaskinen 2016-02-09 12:49:59 UTC
The patch is now applied, I'm marking this bug as fixed.


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.