From 47dffe66aa839c5de96cb1ba0f1341bf2df75bed Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 15 Feb 2017 11:23:44 +0100 Subject: [PATCH] output/alsa: fix race condition on early snd_pcm_writei() error During UnlockActivate() while the mutex is unlocked, the IOThread can set a new error condition, and will never again wake up the OutputThread. This race condition can cause a deadlock in the OutputThread. --- src/output/plugins/AlsaOutputPlugin.cxx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/output/plugins/AlsaOutputPlugin.cxx b/src/output/plugins/AlsaOutputPlugin.cxx index 01dea36ca..b93a5362b 100644 --- a/src/output/plugins/AlsaOutputPlugin.cxx +++ b/src/output/plugins/AlsaOutputPlugin.cxx @@ -1211,6 +1211,12 @@ AlsaOutput::Play(const void *chunk, size_t size) snd_pcm_writei() */ UnlockActivate(); + /* check the error again, because a new one may have + been set while our mutex was unlocked in + UnlockActivate() */ + if (error) + std::rethrow_exception(error); + /* wait for the DispatchSockets() to make room in the ring_buffer */ cond.wait(mutex);