Skip to content

Deadlock in ALSA plugin #56

Description

@NexAdn

I've found a deadlock in the ALSA plugin,
causing the whole program to freeze every time I try to switch the input in OpenSoundMeter.
To trace the issue down,
I've inserted a bunch of std::cout statements in the code,
which also show where the mutexes get locked and unlocked:

Measurement::updateAudio(): async entry
Measurement::updateAudio(): async pre-setCallback
Measurement::updateAudio(): async pre-getInstance
Measurement::updateAudio(): async pre-openInput
audio::Client::openInput(): entry
audio::Client::openInput(): pluginForDevice()
audio::Client::openInput(): targetPlugin->open
0x557750193a90	ALSA
AlsaPlugin::open() entry, 0x557750193ac0 locking
AlsaPlugin::open() locked
AlsaPlugin::open(): Creating new AlsaPCMDevice
AlsaPlugin::open(): starting device
AlsaPlugin::open(): setKeepAlive()
AlsaPlugin::open(): new Stream()
AlsaPlugin::open(): endpoint->open()
AlsaPlugin::open(): Waiting for device->active()
AlsaPlugin::open(): Returning stream, unlocking 0x557750193ac0
audio::Client::openInput(): return
Measurement::updateAudio(): async pre-connect
Measurement::updateAudio(): async pre-emit
Measurement::updateAudio(): async exit
Invalid QML element name "meta::Filter"; type names must begin with an uppercase letter
Invalid QML element name "meta::Measurement"; type names must begin with an uppercase letter
Qt Quick Layouts: Detected recursive rearrange. Aborting after two iterations.
Qt Quick Layouts: Detected recursive rearrange. Aborting after two iterations.
Qt Quick Layouts: Detected recursive rearrange. Aborting after two iterations.
AlsaPCMDevice::start() locking 0x557750193ac0
Measurement::updateAudio(): async entry
Measurement::updateAudio(): async pre-setCallback
Measurement::updateAudio(): async pre-getInstance
Measurement::updateAudio(): async pre-openInput
audio::Client::openInput(): entry
audio::Client::openInput(): pluginForDevice()
audio::Client::openInput(): targetPlugin->open
0x557750193a90	ALSA
AlsaPlugin::open() entry, 0x557750193ac0 locking

as far as I can see it,
the main issue is that the AlsaPCMDevice holds a lock on the mutex AlsaPlugin::m_deviceListMutex as long as it isn't closed.
When switching the device,
the old AlsaPCMDevice isn't closed and thus the mutex isn't unlocked,
causing the deadlock.

Note that I was sometimes unable to reproduce the issue with CONFIG+="debug",
as long as I inserted std::cout statements.
Thus, there is some weird timing issue,
which may cause problems when trying to reproduce the issue.

System: Gentoo Linux with Qt 5.15.5 installed, using OSM version 1.2.1 (tried both the AppImage and self-compiled from master)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions