Bug 239730 - System fails to remove the audio device because some app keeps it opened, kernel enters the endless cycle: unregister: mixer busy Waiting for sound application to exit!
Summary: System fails to remove the audio device because some app keeps it opened, ker...
Status: Closed DUPLICATE of bug 194727
Alias: None
Product: Base System
Classification: Unclassified
Component: usb (show other bugs)
Version: 12.0-RELEASE
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-usb mailing list
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-08-08 23:41 UTC by Yuri Victorovich
Modified: 2019-08-09 07:53 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Yuri Victorovich freebsd_committer 2019-08-08 23:41:16 UTC
I connected the USB audio device through a (possibly unstable) USB hub.
When the USB hub has disconnected the system began to print messages like this:
> Aug  8 15:57:12 sw kernel: pcm3: unregister: mixer busy
> Aug  8 15:57:12 sw kernel: pcm3: Waiting for sound application to exit!

IMHO, this is an entirely wrong behavior.

Once the device disappears, the device file should be just gone. If some application has it opened, the file handle should remain and all subsequent API functions that this application invokes with this file handle should fail. The file handle should disappear when the application would close it. In the next second the same device can reappear, and then any applications should be able to just use it again, regardless of some application that is potentially holding the old instance of it open.

Unregistering the sound device should not print any such messages as it currently prints. Unregistering shouldn't fail just because some application has it open, because this can happen any time.


----system log----
Aug  8 15:53:55 sw kernel: uaudio0: <vendor 0x046d HD Pro Webcam C920, class 239/2, rev 2.00/0.11, addr 2> on usbus0
Aug  8 15:53:55 sw kernel: uaudio0: No playback.
Aug  8 15:53:55 sw kernel: uaudio0: Record: 32000 Hz, 2 ch, 16-bit S-LE PCM format, 2x8ms buffer.
Aug  8 15:53:55 sw kernel: uaudio0: Record: 24000 Hz, 2 ch, 16-bit S-LE PCM format, 2x8ms buffer.
Aug  8 15:53:55 sw kernel: uaudio0: Record: 16000 Hz, 2 ch, 16-bit S-LE PCM format, 2x8ms buffer.
Aug  8 15:53:55 sw kernel: uaudio0: No MIDI sequencer.
Aug  8 15:53:55 sw kernel: pcm3: <USB audio> on uaudio0
Aug  8 15:53:55 sw kernel: uaudio0: No HID volume keys found.
...
Aug  8 15:56:38 sw kernel: ugen0.2: <vendor 0x214b USB2.0 HUB> at usbus0 (disconnected)
Aug  8 15:56:38 sw kernel: uhub2: at uhub0, port 5, addr 1 (disconnected)
Aug  8 15:56:38 sw kernel: ugen0.3: <vendor 0x046d HD Pro Webcam C920> at usbus0 (disconnected)
Aug  8 15:56:38 sw kernel: uaudio0: at uhub2, port 1, addr 2 (disconnected)
Aug  8 15:56:38 sw kernel: pcm3: unregister: mixer busy
Aug  8 15:56:38 sw kernel: pcm3: Waiting for sound application to exit!
Aug  8 15:56:40 sw kernel: pcm3: unregister: mixer busy
Aug  8 15:56:40 sw kernel: pcm3: Waiting for sound application to exit!
Aug  8 15:56:42 sw kernel: pcm3: unregister: mixer busy
Aug  8 15:56:42 sw kernel: pcm3: Waiting for sound application to exit!
Aug  8 15:56:44 sw kernel: pcm3: unregister: mixer busy
Aug  8 15:56:44 sw kernel: pcm3: Waiting for sound application to exit!
Aug  8 15:56:46 sw kernel: pcm3: unregister: mixer busy
Aug  8 15:56:46 sw kernel: pcm3: Waiting for sound application to exit!
Aug  8 15:56:48 sw kernel: pcm3: unregister: mixer busy
Aug  8 15:56:48 sw kernel: pcm3: Waiting for sound application to exit!
Aug  8 15:56:50 sw kernel: pcm3: unregister: mixer busy
Aug  8 15:56:50 sw kernel: pcm3: Waiting for sound application to exit!
Aug  8 15:56:52 sw kernel: pcm3: unregister: mixer busy
Aug  8 15:56:58 sw kernel: pcm3: unregister: mixer busy
Aug  8 15:56:58 sw kernel: pcm3: Waiting for sound application to exit!
Aug  8 15:57:00 sw kernel: pcm3: unregister: mixer busy
Aug  8 15:57:00 sw kernel: pcm3: Waiting for sound application to exit!
Aug  8 15:57:02 sw kernel: pcm3: unregister: mixer busy
Aug  8 15:57:02 sw kernel: pcm3: Waiting for sound application to exit!
Aug  8 15:57:04 sw kernel: pcm3: unregister: mixer busy
Aug  8 15:57:04 sw kernel: pcm3: Waiting for sound application to exit!
Aug  8 15:57:06 sw kernel: pcm3: unregister: mixer busy
Aug  8 15:57:06 sw kernel: pcm3: Waiting for sound application to exit!
Aug  8 15:57:08 sw kernel: pcm3: unregister: mixer busy
Aug  8 15:57:08 sw kernel: pcm3: Waiting for sound application to exit!
Aug  8 15:57:10 sw kernel: pcm3: unregister: mixer busy
Aug  8 15:57:10 sw kernel: pcm3: Waiting for sound application to exit!
Aug  8 15:57:12 sw kernel: pcm3: unregister: mixer busy
Aug  8 15:57:12 sw kernel: pcm3: Waiting for sound application to exit!
Aug  8 15:57:14 sw kernel: pcm3: unregister: mixer busy
Aug  8 15:57:14 sw kernel: pcm3: Waiting for sound application to exit!
Aug  8 15:57:16 sw kernel: pcm3: unregister: mixer busy
Aug  8 15:57:16 sw kernel: pcm3: Waiting for sound application to exit!
Aug  8 15:57:18 sw kernel: pcm3: unregister: mixer busy
Aug  8 15:57:18 sw kernel: pcm3: Waiting for sound application to exit!
Aug  8 15:57:20 sw kernel: pcm3: unregister: mixer busy
Aug  8 15:57:20 sw kernel: pcm3: Waiting for sound application to exit!
Comment 1 Hans Petter Selasky freebsd_committer 2019-08-09 07:34:20 UTC
Hi,

You need to fix the applications! Leaking FDs is not a good option. And also there is a problem with the device naming, that when you do not close /dev/mixerN, that particular device name cannot be reused, causing more problems when enumerating the next USB audio device. This issue is already known. See BUG 194727.

--HPS
Comment 2 Hans Petter Selasky freebsd_committer 2019-08-09 07:34:30 UTC

*** This bug has been marked as a duplicate of bug 194727 ***
Comment 3 Yuri Victorovich freebsd_committer 2019-08-09 07:40:45 UTC
(In reply to Hans Petter Selasky from comment #1)

Applications, unfortunately, can't all be fixed, because they would be anything.
Comment 4 Hans Petter Selasky freebsd_committer 2019-08-09 07:53:04 UTC
The next problem you will face is that the mixer application will just stop working because it never closes the old mixer device :-(

At some point you'll need to fix these. From what I know there are only a few of them around in ports, we have the source code and can submit a patch.

Another approach may be to implement a fixed mixer node using libcuse for example. Right now /dev/mixer is just pointed around to whatever hw.snd.default_unit is like. We can disable /dev/mixer in the kernel by a sysctl similar to (hw.snd.basename_clone) we can make a (hw.snd.mixer_clone), which the wrapper app sets to zero.

Is this something you can do?

--HPS