[New-bugs-announce] [issue7403] Race condition in logging._acquireLock()?

Gavin Panella report at bugs.python.org
Fri Nov 27 12:42:41 CET 2009


New submission from Gavin Panella <gavin at gromper.net>:

The logging module create a global _lock in what looks like a
thread-unsafe manner:

{{{
_lock = None

def _acquireLock():
    """
    Acquire the module-level lock for serializing access to shared data.

    This should be released with _releaseLock().
    """
    global _lock
    if (not _lock) and thread:
        _lock = threading.RLock()
    if _lock:
        _lock.acquire()
}}}

If two threads call _acquireLock() at the same time, and _lock is
None, it's possible that two locks will be created, one of which will
get clobbered.

I think the above could be made thread-safe if written as:

{{{
if thread:
    _lock = threading.RLock()
else:
    _lock = None

def _acquireLock():
    """
    Acquire the module-level lock for serializing access to shared data.

    This should be released with _releaseLock().
    """
    if _lock:
        _lock.acquire()
}}}

----------
components: Library (Lib)
messages: 95764
nosy: allenap
severity: normal
status: open
title: Race condition in logging._acquireLock()?
type: behavior
versions: Python 2.4, Python 2.5, Python 2.6

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue7403>
_______________________________________


More information about the New-bugs-announce mailing list