[New-bugs-announce] [issue43939] Deadlock in logging

DaRoee report at bugs.python.org
Sun Apr 25 12:58:46 EDT 2021

New submission from DaRoee <roee.drucker at gmail.com>:

I've recently encountered a weird bug. To make a long story short, I’ve been using an external package to make sure my threads stop working in time, and appearently it’s been using ctypes.pythonapi.PyThreadState_SetAsyncExc.
There is a slight chance, that this code that is literally injecting an exception in the thread, will throw an exception in the handle function of the logger, right after the acquire. This will make the whole process deadlocked (only the thread with the exception will be able to continue logging) once the other threads try to log.

While I totally understand that this is not a casual use case, I think that the logger should be able to handle situations such as this...
The good news is that I’ve created a test (attached) that once you run it with pytest it’ll reproduce constantly (even though it’s a statistical bug), and the solution for this is relatively easy. Once we change the lock to use context manager the whole action is much more atomic, making the test pass constantly.

I’d be happy to help solve it, and replace locks to context manager usage throughout the file (or whatever the maintainers see fit for this).

components: Library (Lib)
files: reproduction_test.py
messages: 391862
nosy: DaRoee
priority: normal
severity: normal
status: open
title: Deadlock in logging
type: behavior
versions: Python 3.10, Python 3.6, Python 3.7, Python 3.8, Python 3.9
Added file: https://bugs.python.org/file49983/reproduction_test.py

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list