This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Improper locking in logging
Type: behavior Stage:
Components: Library (Lib) Versions: Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: vinay.sajip Nosy List: aronacher, eric.araujo, vinay.sajip
Priority: normal Keywords:

Created on 2010-09-25 13:27 by aronacher, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (4)
msg117364 - (view) Author: Armin Ronacher (aronacher) * (Python committer) Date: 2010-09-25 13:27
I found a a useless lock acquiring in the 27 maintenance branch in logging and a missing one as well:

Logger.removeHandler() locks around a handler lock, however the code executed in this lock is not depending on anything of that lock.  However there is a race condition when two pieces of code try to remove the same handler at the same time because between the if and the remove() no locking takes place.

I would recommend this instead (and also add locking to the addHandler):

    def addHandler(self, hdlr):
        """
        Add the specified handler to this logger.
        """
        _acquireLock()
        try:
            if hdlr not in self.handlers:
                self.handlers.append(hdlr)
        finally:
            _releaseLock()

    def removeHandler(self, hdlr):
        """
        Remove the specified handler from this logger.
        """
        _acquireLock()
        try:
            if hdlr in self.handlers:
                self.handlers.remove(hdlr)
        finally:
            _releaseLock()

I suppose in 3.x there might be something similar.
msg117382 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2010-09-25 17:43
Fix checked into py3k and release27-maint branches, r85012. Thanks!
msg117465 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2010-09-27 19:51
Just to be sure: this does not apply to 3.1?
msg117478 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2010-09-27 21:48
Good call, Éric - fix backported into release31-maint (r85045).
History
Date User Action Args
2022-04-11 14:57:06adminsetgithub: 54154
2010-09-27 21:48:14vinay.sajipsetmessages: + msg117478
2010-09-27 19:52:13eric.araujolinkissue9946 superseder
2010-09-27 19:51:48eric.araujosetnosy: + eric.araujo
messages: + msg117465
2010-09-25 17:43:45vinay.sajipsetstatus: open -> closed
resolution: fixed
messages: + msg117382
2010-09-25 13:27:31aronachercreate