[New-bugs-announce] [issue45835] Race condition in test_queue can lead to test failures

Sam Gross report at bugs.python.org
Wed Nov 17 16:57:20 EST 2021


New submission from Sam Gross <colesbury at gmail.com>:

The test_queue suite has a race condition that can lead to test failures in test_many_threads, test_many_threads_nonblock, and test_many_threads_timeout. Consumers are signaled to exit by a sentinel value (None). The sentinel values are at the end of the input list, but that doesn't mean they are necessarily enqueued at the end of the inter-thread queue when there are multiple "feeder" threads.

In particular, a feeder thread may be delayed in enqueueing a non-sentinel value. The other feeder threads may finish popping and enqueueing the remaining values including all the sentinels, leading to the delayed non-sentinel value arriving AFTER all the sentinels. The "consumer" threads exit before processing all the values leading to the assertion error in run_threads() in test_queue.py:

  self.assertTrue(q.empty())

I will attach a patch that adds a delay in feed() to make the race condition occur more frequently so that the issue is easier to reproduce.

----------
components: Tests
messages: 406498
nosy: colesbury
priority: normal
severity: normal
status: open
title: Race condition in test_queue can lead to test failures
type: behavior
versions: Python 3.10, Python 3.11, Python 3.9

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue45835>
_______________________________________


More information about the New-bugs-announce mailing list