From 4f5bb01622f40196f360dfc3809e947b4cef94d9 Mon Sep 17 00:00:00 2001 From: Matthias Urlichs Date: Wed, 4 Jul 2018 07:14:11 +0200 Subject: [PATCH 1/2] Always force tasks off the queue When queue.get() is cancelled, the task must not be left on the queue. Otherwise an interesting crash will result when the next item is pushed. --- trio/_sync.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/trio/_sync.py b/trio/_sync.py index 8b454109b2..f05d77829f 100644 --- a/trio/_sync.py +++ b/trio/_sync.py @@ -968,7 +968,10 @@ def abort_fn(_): return _core.Abort.SUCCEEDED self._get_wait[task] = None - value = await _core.wait_task_rescheduled(abort_fn) + try: + value = await _core.wait_task_rescheduled(abort_fn) + finally: + self._get_wait.pop(task, None) return value @aiter_compat From 82be61ea76b9db66a33fcc750461c49c993f03f7 Mon Sep 17 00:00:00 2001 From: Matthias Urlichs Date: Wed, 4 Jul 2018 07:24:44 +0200 Subject: [PATCH 2/2] add testcase for #553 --- trio/tests/test_sync.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/trio/tests/test_sync.py b/trio/tests/test_sync.py index 2e28471ecc..cd0a166bf6 100644 --- a/trio/tests/test_sync.py +++ b/trio/tests/test_sync.py @@ -5,6 +5,7 @@ from ..testing import wait_all_tasks_blocked, assert_checkpoints from .. import _core +from .. import _timeouts from .._timeouts import sleep_forever from .._sync import * @@ -407,6 +408,11 @@ async def test_Queue(): q.get_nowait() assert q.empty() + with _timeouts.move_on_after(0.01) as timeout_scope: + await q.get() + assert timeout_scope.cancelled_caught + await q.put("Test for https://github.com/python-trio/trio/pull/553") + async def test_Queue_iter(): q = Queue(1)