From 9933f57dda19dd7e338931705978179be786ee43 Mon Sep 17 00:00:00 2001 From: Eric Frias Date: Fri, 25 Sep 2015 19:14:44 -0400 Subject: [PATCH] In asio worker threads, catch and ignore exceptions thrown by asio handlers. websocketspp code leaks boost exceptions from its handlers which would otherwise terminate the program --- src/asio.cpp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/asio.cpp b/src/asio.cpp index 430147d..0319eaa 100644 --- a/src/asio.cpp +++ b/src/asio.cpp @@ -2,6 +2,7 @@ #include #include #include +#include namespace fc { namespace asio { @@ -102,7 +103,25 @@ namespace fc { asio_thread = new boost::thread( [=]() { fc::thread::current().set_name("asio"); - io->run(); + while (!io->stopped()) + { + try + { + io->run(); + } + catch (const fc::exception& e) + { + elog("Caught unhandled exception in asio service loop: ${e}", ("e", e)); + } + catch (const std::exception& e) + { + elog("Caught unhandled exception in asio service loop: ${e}", ("e", e.what())); + } + catch (...) + { + elog("Caught unhandled exception in asio service loop"); + } + } }); }