Skip to content

Commit

Permalink
In asio worker threads, catch and ignore exceptions thrown by asio
Browse files Browse the repository at this point in the history
handlers.  websocketspp code leaks boost exceptions from its handlers
which would otherwise terminate the program
  • Loading branch information
emfrias committed Sep 25, 2015
1 parent 83a9e4d commit 9933f57
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/asio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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");
}
}
});
}

Expand Down

0 comments on commit 9933f57

Please sign in to comment.