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 a.niederbuehl
Recipients a.niederbuehl, asvetlov, yselivanov
Date 2021-04-30.18:49:44
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1619808584.15.0.419311675075.issue43991@roundup.psfhosted.org>
In-reply-to
Content
If a task gets canceled while holding a lock, the lock is not automatically released. Is that expected, it seems like it could cause a deadlock?

Failing test adapted from Lib/test/test_asyncio/test_locks.py (commit 6bd9288b80):

    def test_acquire_cancel(self):
        lock = asyncio.Lock()
        self.assertTrue(self.loop.run_until_complete(lock.acquire()))

        task = self.loop.create_task(lock.acquire())
        self.loop.call_soon(task.cancel)
        self.assertRaises(
            asyncio.CancelledError,
            self.loop.run_until_complete, task)
        self.assertFalse(lock._waiters)

        # Should the lock get released after cancellation?
        self.assertFalse(lock.locked())

I stumbled upon this while playing around with TLA+.
History
Date User Action Args
2021-04-30 18:49:44a.niederbuehlsetrecipients: + a.niederbuehl, asvetlov, yselivanov
2021-04-30 18:49:44a.niederbuehlsetmessageid: <1619808584.15.0.419311675075.issue43991@roundup.psfhosted.org>
2021-04-30 18:49:44a.niederbuehllinkissue43991 messages
2021-04-30 18:49:44a.niederbuehlcreate