Skip to content

asyncio queue: get/put will not awaken next if interrupted #108042

@orbisvicis

Description

@orbisvicis

Checklist

  • I am confident this is a bug in CPython, not a bug in a third-party project
  • I have searched the CPython issue tracker,
    and am confident this bug has not been reported before

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Output from running 'python -VV' on the command line:

Python 3.11.4 (main, Jun 9 2023, 07:59:55) [GCC 12.3.0]

A clear and concise description of the bug:

If the current putter has an exception thrown (such as when the task awaiting put() has an exception thrown) and the queue isn't full (which can happen if another task put()s before the current task is rewoken), then the queue must wake up the next putter, because otherwise nothing else will wake up the next putter. This line is responsible for this:

if not self.full() and not putter.cancelled():

Unfortunately that condition - specifically not putter.cancelled() - will never be met because just before, this:

putter.cancel() # Just in case putter is not done yet.

This affects both put() and get(). I propose moving cancel() to just before the raise.

There is no test case - this is something I noticed while reading asyncio/queue.py.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions