From 72c96978336990f59d819bf4b9ce632b4550cd5f Mon Sep 17 00:00:00 2001 From: Alan Conway Date: Mon, 21 Mar 2011 18:05:38 +0000 Subject: QPID-3147: Misconfigured tracing/logging can lead to hung threads in logging stack The hang was caused by re-entrant attempts to initialize the Logger singleton when an exception was thrown during logger configuration. The fix is to disable exception logging temporarily while the logger is constructed. git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@1083884 13f79535-47bb-0310-9956-ffa450edef68 --- cpp/src/qpid/log/Logger.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'cpp/src/qpid/log/Logger.cpp') diff --git a/cpp/src/qpid/log/Logger.cpp b/cpp/src/qpid/log/Logger.cpp index 2217cdddbd..2339a62114 100644 --- a/cpp/src/qpid/log/Logger.cpp +++ b/cpp/src/qpid/log/Logger.cpp @@ -22,6 +22,7 @@ #include "qpid/memory.h" #include "qpid/sys/Thread.h" #include "qpid/sys/Time.h" +#include "qpid/DisableExceptionLogging.h" #include #include #include @@ -48,11 +49,16 @@ Logger& Logger::instance() { } Logger::Logger() : flags(0) { + // Disable automatic logging in Exception constructors to avoid + // re-entrant use of logger singleton if there is an error in + // option parsing. + DisableExceptionLogging del; + // Initialize myself from env variables so all programs // (e.g. tests) can use logging even if they don't parse // command line args. Options opts(""); - opts.parse(0, 0); + opts.parse(0, 0); configure(opts); } @@ -73,7 +79,7 @@ void Logger::log(const Statement& s, const std::string& msg) { std::ostringstream os; if (!prefix.empty()) os << prefix << ": "; - if (flags&TIME) + if (flags&TIME) qpid::sys::outputFormattedNow(os); if (flags&LEVEL) os << LevelTraits::name(s.level) << " "; @@ -140,7 +146,7 @@ void Logger::configure(const Options& opts) { Options o(opts); if (o.trace) o.selectors.push_back("trace+"); - format(o); + format(o); select(Selector(o)); setPrefix(opts.prefix); options.sinkOptions->setup(this); -- cgit v1.2.1