[issue23095] [Windows] asyncio: race condition when cancelling a _WaitHandleFuture

STINNER Victor report at bugs.python.org
Mon Jan 26 17:58:52 CET 2015


STINNER Victor added the comment:

Pseudo-code:
---
handle = ...
fut = proactor.wait_for_handle(handle)
fut.cancel()
loop.close()
---

Windows functions called in this code:

- A: call RegisterWaitForSingleObject() on an handle
- A: call UnregisterWaitEx() with an event
- B: call RegisterWaitForSingleObject() on this event
- B: the wait on this event completes: the completion is signaled with PostToQueueCallback() (our internal callback passed to RegisterWaitForSingleObject())
- A: _unregister_wait_cb() is called on the future A
- (but the wait on the object A is never signaled by PostToQueueCallback())

In short, UnregisterWaitEx() is called before the callback passed to RegisterWaitForSingleObject() is called. In this case, the callback is never called, and so the completion of the wait is never signaled.

Internally, RegisterWaitForSingleObject() is implemented as a pool of threads calling WaitForMultipleObjects(). The default limit for the pool is 500 threads. WaitForMultipleObjects() is limited to 64 objects. Each thread uses a timer and computes a timeout. The timer is awaken to cancel a wait.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue23095>
_______________________________________


More information about the Python-bugs-list mailing list