Description
I've tried running the test suite with Python 3.8.0a3 (on Fedora 30, pytest-cov master, pytest==4.5.0, coverage==4.5.3). While digging into failures I noticed the following race condition.
Solving it doesn't quite fix the tests for me, but I believe it's valid.
cleanup()
and the signal handler _signal_cleanup_handler()
can enter an infinite recursion if a signal is delivered at the wrong time.
Trace when cleanup
is called (with _cleanup_in_progress
False and _pending_signal
None):
_cleanup_in_progress = True
- a signal is delivered now
_signal_cleanup_handler
runs_cleanup_in_progress
is True, so the handler only sets_pending_signal
_cleanup(_active_cov)
runs_active_cov = None
_cleanup_in_progress = False
_pending_signal
is set, so we call_signal_cleanup_handler()
, with_cleanup_in_progress
False and_pending_signal
set:_cleanup_in_progress
is False, so we callcleanup()
:_cleanup_in_progress = True
_cleanup(_active_cov)
_active_cov = None
_cleanup_in_progress = False
_pending_signal
is still set, so call_signal_cleanup_handler()
, again with_cleanup_in_progress
False and_pending_signal
set. This leads to infinite recursion.
The solution could be setting _cleanup_in_progress = False
after the if _pending_signal
block, or setting _pending_signal = None
before calling _signal_cleanup_handler
.
I'm not very familiar with the code and what it's trying to do, so I don't know what a good fix would be (if any).