cpython/Lib/asyncio
Victor Stinner d0a28dee78 Issue #23095, asyncio: Rewrite _WaitHandleFuture.cancel()
This change fixes a race conditon related to _WaitHandleFuture.cancel() leading
to Python crash or "GetQueuedCompletionStatus() returned an unexpected event"
logs. Before, the overlapped object was destroyed too early, it was possible
that the wait completed whereas the overlapped object was already destroyed.
Sometimes, a different overlapped was allocated at the same address, leading to
unexpected completition.

_WaitHandleFuture.cancel() now waits until the wait is cancelled to clear its
reference to the overlapped object. To wait until the cancellation is done,
UnregisterWaitEx() is used with an event instead of UnregisterWait().

To wait for this event, a new _WaitCancelFuture class was added. It's a
simplified version of _WaitCancelFuture. For example, its cancel() method calls
UnregisterWait(), not UnregisterWaitEx(). _WaitCancelFuture should not be
cancelled.

The overlapped object is kept alive in _WaitHandleFuture until the wait is
unregistered.

Other changes:

* Add _overlapped.UnregisterWaitEx()
* Remove fast-path in IocpProactor.wait_for_handle() to immediatly set the
  result if the wait already completed. I'm not sure that it's safe to
  call immediatly UnregisterWaitEx() before the completion was signaled.
* Add IocpProactor._unregistered() to forget an overlapped which may never be
  signaled, but may be signaled for the next loop iteration. It avoids to
  block forever IocpProactor.close() if a wait was cancelled, and it may also
  avoid some "... unexpected event ..." warnings.
2015-01-21 23:39:51 +01:00
..
__init__.py Issue #23046: Expose the BaseEventLoop class in the asyncio namespace 2015-01-06 01:03:58 +01:00
base_events.py asyncio: pyflakes, remove unused import 2015-01-21 23:39:16 +01:00
base_subprocess.py asyncio: sync with Tulip 2015-01-15 00:04:21 +01:00
constants.py asyncio: Pause accepting whenever accept() returns certain errors. Fixes asyncio issue #78. 2013-11-01 14:12:50 -07:00
coroutines.py asyncio: Truncate to 80 columns 2015-01-09 00:09:10 +01:00
events.py Issue #23074: asyncio.get_event_loop() now raises an exception if the thread 2014-12-18 01:20:10 +01:00
futures.py Issue #23209: Break some reference cycles in asyncio. Patch written by Martin 2015-01-09 21:34:27 +01:00
locks.py Issue #22369: Change "context manager protocol" to "context management protocol". 2014-09-10 23:43:41 +03:00
log.py
proactor_events.py asyncio: Enhance BaseProactorEventLoop._loop_self_reading() 2015-01-21 23:38:37 +01:00
protocols.py asyncio: Fix spelling and typos. 2014-02-18 22:27:48 -05:00
queues.py asyncio: sync with Tulip 2015-01-09 01:42:52 +01:00
selector_events.py asyncio: pyflakes, remove unused import 2015-01-21 23:39:16 +01:00
sslproto.py SSLProtocol: set the _transport attribute in the constructor 2015-01-15 13:16:27 +01:00
streams.py Backout changeset 6ab2575bc12b 2015-01-15 21:50:19 +01:00
subprocess.py Issue #23242: asyncio.SubprocessStreamProtocol now closes the subprocess 2015-01-15 13:16:02 +01:00
tasks.py Closes #23219: cancelling asyncio.wait_for() now cancels the task 2015-01-15 16:29:10 +01:00
test_utils.py asyncio: sync with Tulip 2015-01-15 00:04:21 +01:00
transports.py asyncio: Move loop attribute to _FlowControlMixin 2014-11-05 15:27:41 +01:00
unix_events.py asyncio: Close the transport on subprocess creation failure 2015-01-15 14:24:22 +01:00
windows_events.py Issue #23095, asyncio: Rewrite _WaitHandleFuture.cancel() 2015-01-21 23:39:51 +01:00
windows_utils.py asyncio: sync with Tulip 2015-01-15 00:04:21 +01:00