Skip to content

Commit

Permalink
rethrow unwind exception
Browse files Browse the repository at this point in the history
On Linux with pthread library spdlog causes an SIGABORT and crashes
the application in case it catches a thread specific cancellation
exception in a critical execution phase while in a try/catch block
in spdlog/detail/logger_impl.h

The exception is caught by some general catch(...) clause where
it is NOT rethrown.

However rethrowing these kind of exception is mandatory, otherwise
an abort will be caused by the glibc.
  • Loading branch information
manuel-schiller committed Oct 24, 2017
1 parent 9688689 commit 935e9cc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
6 changes: 6 additions & 0 deletions include/spdlog/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@
#define SPDLOG_DEPRECATED
#endif

#ifdef __linux__
#include <cxxabi.h>
#define SPDLOG_CATCH_ALL catch (abi::__forced_unwind&) { throw; } catch (...)
#else // __linux__
#define SPDLOG_CATCH_ALL catch (...)
#endif // __linux__

#include "spdlog/fmt/fmt.h"

Expand Down
9 changes: 5 additions & 4 deletions include/spdlog/details/logger_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include <memory>
#include <string>


// create logger with given name, sinks and the default pattern formatter
// all other ctors will call this one
template<class It>
Expand Down Expand Up @@ -78,7 +77,7 @@ inline void spdlog::logger::log(level::level_enum lvl, const char* fmt, const Ar
{
_err_handler(ex.what());
}
catch (...)
SPDLOG_CATCH_ALL
{
_err_handler("Unknown exception");
}
Expand All @@ -98,7 +97,7 @@ inline void spdlog::logger::log(level::level_enum lvl, const char* msg)
{
_err_handler(ex.what());
}
catch (...)
SPDLOG_CATCH_ALL
{
_err_handler("Unknown exception");
}
Expand All @@ -119,7 +118,7 @@ inline void spdlog::logger::log(level::level_enum lvl, const T& msg)
{
_err_handler(ex.what());
}
catch (...)
SPDLOG_CATCH_ALL
{
_err_handler("Unknown exception");
}
Expand Down Expand Up @@ -566,3 +565,5 @@ inline const std::vector<spdlog::sink_ptr>& spdlog::logger::sinks() const
{
return _sinks;
}

#undef SPDLOG_CATCH_ALL

1 comment on commit 935e9cc

@gabime
Copy link
Owner

@gabime gabime commented on 935e9cc Oct 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the error handler wont be called according to this macro (the macro just throws). please fix it too and i will merge

Please sign in to comment.