[issue43939] Deadlock in logging

2021-04-25 Thread DaRoee

New submission from DaRoee :

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 
<https://bugs.python.org/issue43939>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43939] Deadlock in logging

2021-04-25 Thread DaRoee


Change by DaRoee :


--
nosy: +vinay.sajip

___
Python tracker 
<https://bugs.python.org/issue43939>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43939] Deadlock in logging

2021-04-27 Thread DaRoee


DaRoee  added the comment:

Ha! Already gave them my analysis, and stopped using that package since.
While I certainly think this is not the trivial, basic usage, and that the 
pattern used for the lock is common (and part of some PEP if I remember 
correctly), I'm kind of puzzled on that fact that context manager solves it. 
The test will pass constantly once the change is made (even though it looks 
like RLock __enter__ is just calling the acquire function), and I overall think 
this is a good change to do in the Handler class, even it's just for self.lock 
(can we find and understand why the last proposal was rejected?).

I'll submit a PR in a few days, but was wondering on the usage of the lock, and 
that it doesn't always exists on `self`. Anyway, I assume these are questions 
that we can continue discussing in the PR if you also think this is a good 
direction..

--

___
Python tracker 
<https://bugs.python.org/issue43939>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com