ACE VERSION: 6.0.1
ACE VERSION: 6.1.5
HOST MACHINE and OPERATING SYSTEM:
Linux Debian 6.0 on x86_64
COMPILER NAME AND VERSION (AND PATCHLEVEL):
THE $ACE_ROOT/ace/config.h FILE:
THE $ACE_ROOT/include/makeinclude/platform_macros.GNU FILE:
buildbits ?= 64
DOES THE PROBLEM AFFECT:
SYNOPSIS: Race condition in ACE_Logging_Strategy::handle_timeout
results in occasional core dumps, and random file lengths
We use ACE_Logging_Strategy to limit log file size to 100MB, and default
10 minute file-size-polling interval.
Our program is multi-threaded with very low activity - there are couple
of timers running, and they keep invoking ACE_TRACE. We notice that
files are prematurely being rotated, with sizes much smaller than the
100MB configured size.
Also, there are occasional core dumps (see stack trace attached).
Looking at ACE_Logging_Strategy::handle_timeout function, I notice that
the test for the file length is invoked while Log_Msg is *not* being locked.
401#if defined (ACE_LACKS_IOSTREAM_TOTALLY)
402 if ((size_t) ACE_OS::ftell (this->log_msg_->msg_ostream ()) >
404 if ((size_t) this->log_msg_->msg_ostream ()->tellp () >
405#endif /* ACE_LACKS_IOSTREAM_TOTALLY */
407 // Lock out any other logging.
408 if (this->log_msg_->acquire ())
409 ACE_ERROR_RETURN ((LM_ERROR,
410 ACE_TEXT ("Cannot acquire lock!\n")),
Line 404: invoking tellp() on ostream is not thread safe - it actually
invokes setpos. tellp() returns implementation specific streampos, which
may not be an integer, but can be constructed from (-1), since in case
tellp() fails, it will return streampos(-1).
Derive MyLoggingStrategy from ACE_Logging_Strategy, enclose
Logging_Straregy::handle_timeout into MyLoggingStrategy::handle_timeout,
and invoke this->log_msg_->acquire() before invoking
Sample test program shows that tellp() is not thread safe.
One thread writes messages to a file, other thread runs tellp(). Must be
run on a machine with more than one CPU. It core dumps in less than 5 sec.
- stack trace of our application with ace-6.0.1
- sample code for tellp not being thread safe
- attached patch for Logging_Strategy.cpp for ace-6.1.5