PulseAudio ALSA plugin opens and closes the PulseAudio sink when recovering from underrun

Bug #503174 reported by Alistair Buxton on 2010-01-05
This bug affects 4 people
Affects Status Importance Assigned to Milestone
alsa-plugins (Ubuntu)

Bug Description

Binary package hint: pulseaudio

When using the PulseAudio ALSA plugin, the sink can be seen "flickering" in gnome-volume-control-applet and pavucontrol as it is opened and closed. This causes stuttering sound if the app is playing anything. I have observed this bug on two different machines, one Intel 32 bit and one AMD 64 bit. See the following videos:


ProblemType: Bug
Architecture: amd64
 **** List of CAPTURE Hardware Devices ****
 card 0: SB [HDA ATI SB], device 0: VT1708S Analog [VT1708S Analog]
   Subdevices: 2/2
   Subdevice #0: subdevice #0
   Subdevice #1: subdevice #1
 /dev/snd/controlC0: al 2158 F.... pulseaudio
 /dev/snd/pcmC0D0p: al 2158 F...m pulseaudio
 Card hw:0 'SB'/'HDA ATI SB at 0xf9ff4000 irq 16'
   Mixer name : 'VIA VT1708S'
   Components : 'HDA:11060397,1043836c,00100000'
   Controls : 36
   Simple ctrls : 20
Date: Tue Jan 5 00:48:41 2010
DistroRelease: Ubuntu 9.10
InstallationMedia: Ubuntu 9.10 "Karmic Koala" - Release amd64 (20091027)
NonfreeKernelModules: nvidia
Package: pulseaudio 1:0.9.19-0ubuntu4
ProcVersionSignature: Ubuntu 2.6.31-16.53-generic
SourcePackage: pulseaudio
Uname: Linux 2.6.31-16-generic x86_64

Alistair Buxton (a-j-buxton) wrote :

What applications are you using via the pulseaudio alsa plugin? I believe issues with this problem have been found recently, but as far as I understand things, only some applications cause the plugin to hit such issues.

In the videos I am using spotify in wine-1.2 and pcsx-reloaded compiled from source.

Alistair Buxton (a-j-buxton) wrote :

I suspect that this error is caused by a buffer underrun. It seems to happen most often in applications which use a lot of CPU. It seems that if a buffer underrun occurs, alsa-plugin closes the sink and reopens it when the buffer is filled again. I'm not sure about this, it's just a theory.

Alistair Buxton (a-j-buxton) wrote :

I can confirm that the opening/closing of the sink happens when a buffer underrun happens. The only way I can prevent this from happening is by using a buffer approximately 1 second long (which is the default length) but then audio lags behind by 1 second.

Alistair Buxton (a-j-buxton) wrote :

Here is a test program which causes the underrun and crazy flickering to happen.

David Henningsson (diwic) wrote :

Hi Alistair, thanks for reporting this bug and providing a test case. However I've tried your test program under current Lucid, and I hear a perfect tone with no flickering or underrun.

David Henningsson (diwic) wrote :

I have now tried it under Karmic as well and found no underruns there either. Interesting is however that under Karmic your test program outputs "ALSA buffer size: 33791" but under Lucid it is "ALSA buffer size: 1048576".

affects: pulseaudio (Ubuntu) → alsa-plugins (Ubuntu)

It is extremely interesting that the buffer is so large on Lucid. When the buffer is 33791 and the playback is 44100 this causes nearly a second delay between audio being buffered and being played. With a 1048576 buffer that will be 23 seconds.

Also, while the underrunning may well be hardware dependent, PulseAudio closing and reopening the audio sink when a buffer underrun happens is not, and means that a program such as the example I posted can do a denial of service attack on Pulse just by intentionally underrunning the buffer repeatedly - which causes Pulse to eat 100% CPU opening and closing the sink.

Alistair Buxton (a-j-buxton) wrote :

Also, perhaps I wasn't clear. The example program does not underrun repeatedly when PulseAudio is not running. It may underrun very occasionally causing a single pop, usually only immediately after running it.

When PulseAudio is running, as soon as it underruns once, the load caused by PA opening and closing the sink causing another underrun to happen instantly, and so on. And it goes into a loop it cannot recover from, leading to the flickering.

Please reproduce this symptom using the latest alsa-source deb from
Lucid, which has some pretty significant pcm core+lib updates based on
hw ptr errata. You can grab it, install it, and compile (look in
/usr/src) it, reboot, etc.

Alistair Buxton (a-j-buxton) wrote :

OK, I have finally got the alsa-source package working. It fixes the awful latency with my card and makes all the apps I tried work correctly, including my example.

However, it does not stop pulseaudio from reopening sinks when a buffer underrun occurs.

Alistair Buxton (a-j-buxton) wrote :

Here is a modified example which deliberately underruns the buffer 200 times per second. This is what top looks like on a 3.2ghz Phenom II:

 2613 al 20 0 274m 5760 3636 S 56 0.1 4:21.61 pulseaudio
 2152 root 20 0 886m 33m 14m S 6 0.8 4:18.38 Xorg
 2629 al 20 0 323m 34m 7456 S 6 0.9 0:54.97 gnome-settings-
 2750 al 20 0 287m 38m 9572 S 5 1.0 0:42.42 gnome-volume-co
 2722 al 20 0 316m 52m 17m S 4 1.3 1:23.50 compiz.real
 2828 al 20 0 215m 20m 10m S 4 0.5 0:24.41 gnome-terminal
 3464 al 20 0 132m 2920 2188 S 3 0.1 0:14.89 alsatest

If pavucontrol is running things get a lot worse:

 3483 al 20 0 297m 24m 15m R 91 0.6 0:05.29 pavucontrol
 2613 al 20 0 338m 9944 7820 S 35 0.2 4:42.49 pulseaudio
 2152 root 20 0 887m 33m 14m R 20 0.9 4:21.08 Xorg
 2629 al 20 0 324m 35m 7456 S 11 0.9 0:57.65 gnome-settings-
 2722 al 20 0 316m 52m 17m S 9 1.3 1:24.36 compiz.real
 2750 al 20 0 288m 39m 9572 R 6 1.0 0:44.13 gnome-volume-co
 3464 al 20 0 132m 2936 2188 S 5 0.1 0:16.37 alsatest

This is while running the suggested alsa-source modules.

David Henningsson (diwic) wrote :

I can confirm that when recovering from an underrun, the pulseaudio sink is closed and reopened. This seems unnecessary to me and is a minor annoyance, but that is less important than fighting the underruns themselves, as I'm trying to do in bug #485488 .

summary: - PulseAudio ALSA plugin opens and closes the PulseAudio sink several
- times per second for no reason
+ PulseAudio ALSA plugin opens and closes the PulseAudio sink when
+ recovering from underrun
Changed in alsa-plugins (Ubuntu):
importance: Undecided → Low
status: New → Triaged
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package alsa-plugins - 1.0.22-0ubuntu6

alsa-plugins (1.0.22-0ubuntu6) lucid; urgency=low

  [ Daniel T Chen ]
  * Add e3b3c40-check-null-before-dereference.patch

  [ David Henningsson ]
  * Add lp464008lp503174.patch (LP: #464008, #503174)
 -- Daniel T Chen <email address hidden> Sun, 28 Feb 2010 17:03:48 -0500

Changed in alsa-plugins (Ubuntu):
status: Triaged → Fix Released
Rich Wales (richw) wrote :

Is there any way to get a fix for this bug in Karmic?

Rich Wales (richw) wrote :

FWIW, there's a related bug (#539932) in Karmic Backports: "Please backport libasound2-plugins (source alsa-plugins)".

scottyg (gabe-scott) on 2010-05-11
Changed in alsa-plugins (Ubuntu):
status: Fix Released → Fix Committed
Chris Hermansen (c-hermansen) wrote :

Not sure this is completely fixed; I have underruns as described above in Lucid. In fact I just listened to one now.

May 11 19:46:43 temuko pulseaudio[1311]: alsa-sink.c: Underrun!
May 11 19:46:43 temuko pulseaudio[1311]: alsa-sink.c: Increasing wakeup watermark to 45.99 ms

For example.

Willing to test / fiddle / etc!!!

David Henningsson (diwic) wrote :

@Chris Hermansson: you're having an underrun in a different layer, which is a different issue. If the underruns are frequently enough to annoy you, please file a separate bug (and include relevant syslog entries). Thanks!

With these patches the alsa plugin does not exhibit this problem anymore. But once using pulseaudio Jack sink, I can confirm a very similar behaviour.

I have no Idea if it can be related to this problem, tough.

David Henningsson (diwic) wrote :

@Adriano: So if you can reproduce a jack <-> pulse bug in Maverick (which has a different Jack implementation), please file a separate bug for that. Thanks!

Changed in alsa-plugins (Ubuntu):
status: Fix Committed → Fix Released
Damian (thedevil259) on 2013-12-24
Changed in alsa-plugins (Ubuntu):
assignee: nobody → Damian (thedevil259)
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers