classification
Title: Race condition in logging._acquireLock()?
Type: behavior Stage:
Components: Library (Lib) Versions: Python 2.4, Python 2.6, Python 2.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: vinay.sajip Nosy List: allenap, vinay.sajip
Priority: normal Keywords:

Created on 2009-11-27 11:42 by allenap, last changed 2009-11-27 20:39 by vinay.sajip. This issue is now closed.

Messages (3)
msg95764 - (view) Author: Gavin Panella (allenap) Date: 2009-11-27 11:42
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()
}}}
msg95769 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2009-11-27 14:04
Thanks Gavin, fix checked into trunk, py3k and release26-maint (r76551).
msg95774 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2009-11-27 20:39
Fixes now also in release24-maint and release25-maint (as of r76555).
History
Date User Action Args
2009-11-27 20:39:30vinay.sajipsetmessages: + msg95774
2009-11-27 14:05:39vinay.sajipsetstatus: open -> closed
resolution: fixed
2009-11-27 14:04:42vinay.sajipsetmessages: + msg95769
2009-11-27 11:44:40pitrousetassignee: vinay.sajip

nosy: + vinay.sajip
2009-11-27 11:42:39allenapcreate