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.

Author dmaurer
Recipients dmaurer
Date 2022-04-07.08:44:47
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1649321087.35.0.157706510591.issue47246@roundup.psfhosted.org>
In-reply-to
Content
I have observed an `AssertionError (assert self._is_stopped)` in `threading.Thread._wait_for_tstate_lock`. This indicates that Python's internal state has been corrupted.

The analysis revealed the following race condition:
`_wait_for_tstate:lock` contains the code:
```
                lock.release()
                self._stop()
```
The `lock.release()` allows a conflicting call to execute. If this happens before `self._stop()` has executed `self._is_stopped = True`, the `AssertionError` is raised.

I suggest to give `_stop` an additional parameter `locked` with default `False`. In indicates whether the caller holds the `tstate_lock`. If this is the case, `_stop` releases the lock after it has ensured a consistent state (esspecially set `_is_stopped` to `True`). With this modification to `_stop` the two lines above can be replaced by `self._stop(locked=True)`.
History
Date User Action Args
2022-04-07 08:44:47dmaurersetrecipients: + dmaurer
2022-04-07 08:44:47dmaurersetmessageid: <1649321087.35.0.157706510591.issue47246@roundup.psfhosted.org>
2022-04-07 08:44:47dmaurerlinkissue47246 messages
2022-04-07 08:44:47dmaurercreate