From f61eed1a82313f3d90b49bd7c3454d9e309a0afe Mon Sep 17 00:00:00 2001 From: borine <32966433+borine@users.noreply.github.com> Date: Fri, 12 May 2023 10:17:45 +0100 Subject: [PATCH] input/plugins/Alsa: catch all exceptions snd_pcm_poll_descriptors_revents() may return any error code; the ALSA docs do not constrain the permitted values. A 'hw' device will only ever return an error if the pfd array passed in is invalid (-EINVAL), but other I/O plugins may return arbitary errors. For example a network-based device may return -EPIPE etc. The resulting exception thrown by AlsaNonBlockPcm::DispatchSockets() must be caught to prevent the mpd process from being aborted. --- src/input/plugins/AlsaInputPlugin.cxx | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/input/plugins/AlsaInputPlugin.cxx b/src/input/plugins/AlsaInputPlugin.cxx index 06ff8649c..60cedbf4a 100644 --- a/src/input/plugins/AlsaInputPlugin.cxx +++ b/src/input/plugins/AlsaInputPlugin.cxx @@ -219,7 +219,7 @@ AlsaInputStream::PrepareSockets() noexcept void AlsaInputStream::DispatchSockets() noexcept -{ +try { non_block.DispatchSockets(*this, capture_handle); const std::scoped_lock protect(mutex); @@ -238,16 +238,17 @@ AlsaInputStream::DispatchSockets() noexcept if (n_frames == -EAGAIN) return; - if (Recover(n_frames) < 0) { - postponed_exception = std::make_exception_ptr(std::runtime_error("PCM error - stream aborted")); - InvokeOnAvailable(); - return; - } + if (Recover(n_frames) < 0) + throw std::runtime_error("PCM error - stream aborted"); } size_t nbytes = n_frames * frame_size; CommitWriteBuffer(nbytes); } +catch (...) { + postponed_exception = std::current_exception(); + InvokeOnAvailable(); +} inline int AlsaInputStream::Recover(int err)