This is an automated email from the ASF dual-hosted git repository. martinzink pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/nifi-minifi-cpp.git
commit fa67674eb4a189b58a635d3cea9f07031c6c4179 Author: Gabor Gyimesi <gamezb...@gmail.com> AuthorDate: Mon Nov 6 13:58:18 2023 +0100 MINIFICPP-2235 Remove race condition from MiNiFi Controller Closes #1688 Signed-off-by: Martin Zink <martinz...@apache.org> --- libminifi/src/c2/ControllerSocketProtocol.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/libminifi/src/c2/ControllerSocketProtocol.cpp b/libminifi/src/c2/ControllerSocketProtocol.cpp index ea75df0e4..3cff74e68 100644 --- a/libminifi/src/c2/ControllerSocketProtocol.cpp +++ b/libminifi/src/c2/ControllerSocketProtocol.cpp @@ -78,9 +78,10 @@ ControllerSocketProtocol::~ControllerSocketProtocol() { } void ControllerSocketProtocol::stopListener() { - io_context_.stop(); if (acceptor_) { - acceptor_->close(); + asio::post(io_context_, [this] { + acceptor_->close(); + }); } if (server_thread_.joinable()) { server_thread_.join(); @@ -92,6 +93,10 @@ asio::awaitable<void> ControllerSocketProtocol::startAccept() { while (true) { auto [accept_error, socket] = co_await acceptor_->async_accept(utils::net::use_nothrow_awaitable); if (accept_error) { + if (accept_error == asio::error::operation_aborted || accept_error == asio::error::bad_descriptor) { + logger_->log_debug("Controller socket accept aborted"); + co_return; + } logger_->log_error("Controller socket accept failed with the following message: '{}'", accept_error.message()); continue; } @@ -119,6 +124,10 @@ asio::awaitable<void> ControllerSocketProtocol::startAcceptSsl(std::shared_ptr<m while (true) { // NOLINT(clang-analyzer-core.NullDereference) suppressing asio library linter warning auto [accept_error, socket] = co_await acceptor_->async_accept(utils::net::use_nothrow_awaitable); if (accept_error) { + if (accept_error == asio::error::operation_aborted || accept_error == asio::error::bad_descriptor) { + logger_->log_debug("Controller socket accept aborted"); + co_return; + } logger_->log_error("Controller socket accept failed with the following message: '{}'", accept_error.message()); continue; }