From 33f06d0ffa0babf4a74b98223c8f8ff606b87cdb Mon Sep 17 00:00:00 2001 From: Razvan Becheriu Date: Mon, 30 Oct 2023 21:24:50 +0200 Subject: [PATCH] [#3112] catch all exception when running IOService run, run_one and poll --- src/lib/asiolink/io_service_thread_pool.cc | 23 ++++++++++++++++++---- src/lib/process/d_controller.cc | 8 +++++++- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/lib/asiolink/io_service_thread_pool.cc b/src/lib/asiolink/io_service_thread_pool.cc index 8baf720840..8919385cff 100644 --- a/src/lib/asiolink/io_service_thread_pool.cc +++ b/src/lib/asiolink/io_service_thread_pool.cc @@ -164,7 +164,12 @@ IoServiceThreadPool::setState(State state) { case State::PAUSED: { // Stop IOService. if (!io_service_->stopped()) { - io_service_->poll(); + try { + io_service_->poll(); + } catch (...) { + // Catch all exceptions. + // Logging is not available. + } io_service_->stop(); } @@ -180,7 +185,12 @@ IoServiceThreadPool::setState(State state) { case State::STOPPED: { // Stop IOService. if (!io_service_->stopped()) { - io_service_->poll(); + try { + io_service_->poll(); + } catch (...) { + // Catch all exceptions. + // Logging is not available. + } io_service_->stop(); } @@ -215,8 +225,13 @@ IoServiceThreadPool::threadWork() { } } - // Run the IOService. - io_service_->run(); + try { + // Run the IOService. + io_service_->run(); + } catch (...) { + // Catch all exceptions. + // Logging is not available. + } { std::unique_lock lck(mutex_); diff --git a/src/lib/process/d_controller.cc b/src/lib/process/d_controller.cc index 420442c132..26f371fb8e 100644 --- a/src/lib/process/d_controller.cc +++ b/src/lib/process/d_controller.cc @@ -837,7 +837,13 @@ DControllerBase::~DControllerBase() { } io_signal_set_.reset(); - getIOService()->poll(); + try { + getIOService()->poll(); + } catch (...) { + // Don't want to throw exceptions from the destructor. The process + // is shutting down anyway. + ; + } } std::string