bugfix: fix cancelled tasks pending forever#161
Conversation
1f7f3a2 to
1ffb060
Compare
|
This looks good. Please add a newsfragment ( |
When an AsyncHandle is cancelled, _main_loop_one drops it at `if obj._cancelled: return` without running `_run`, leaving the result_future pending forever. The fix is to always run `AsyncHandle._run`.
1ffb060 to
0265af1
Compare
Thanks Josh - I've done both. Please let me know if the formatting on the newsfragment needs work. |
|
Hey @ngtrunghuan, it looks like that was the first time we merged one of your PRs! Thanks so much! 🎉 🎂 If you want to keep contributing, we'd love to have you. So, I just sent you an invitation to join the python-trio organization on Github! If you accept, then here's what will happen:
If you want to read more, here's the relevant section in our contributing guide. Alternatively, you're free to decline or ignore the invitation. You'll still be able to contribute as much or as little as you like, and I won't hassle you about joining again. But if you ever change your mind, just let us know and we'll send another invitation. We'd love to have you, but more importantly we want you to do whatever's best for you. If you have any questions, well... I am just a humble Python script, so I probably can't help. But please do post a comment here, or in our chat, or on our forum, whatever's easiest, and someone will help you out! |
When an
AsyncHandleis cancelled before the_main_loopis able to dequeue it (often due to heavy CPU load),trio-asynciocurrently leaves the underlyingasyncio.Futurehanging in thePENDINGstate forever, preventing the cancellation to travel upwards back into thetrioloop, leading to us missing task cancellation/completion. Specifically,_main_loop_onegreedily drops it atif obj._cancelled: returnwithout running_run, leaving the result_future pending forever. The fix is to always runAsyncHandle._run.The change includes
tests/test_trio_asyncio.py::test_async_handle_cancelled_before_dequeuethat forces a cancellation before the_main_loophas a chance to dequeue the pending task.