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
This commit is contained in:
Eric Frias 2015-09-25 19:14:44 -04:00
parent 83a9e4d7c8
commit 9933f57dda

View file

@ -2,6 +2,7 @@
#include <fc/thread/thread.hpp>
#include <boost/thread.hpp>
#include <fc/log/logger.hpp>
#include <fc/exception/exception.hpp>
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");
}
}
});
}