[Python-checkins] gh-98703: Fix asyncio proactor_events calling _call_connection_lost multiple times (GH-98704)

miss-islington webhook-mailer at python.org
Wed Oct 26 23:04:49 EDT 2022


https://github.com/python/cpython/commit/08ce791f94618a6f553a9017fcaf5b84e85cb602
commit: 08ce791f94618a6f553a9017fcaf5b84e85cb602
branch: 3.11
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: miss-islington <31488909+miss-islington at users.noreply.github.com>
date: 2022-10-26T20:04:43-07:00
summary:

gh-98703: Fix asyncio proactor_events calling _call_connection_lost multiple times (GH-98704)


Co-authored-by: Kumar Aditya <59607654+kumaraditya303 at users.noreply.github.com>
(cherry picked from commit 8a755423eba8e19704d96905730cf7f50083eb23)

Co-authored-by: Ken Jin <kenjin at python.org>

files:
A Misc/NEWS.d/next/Library/2022-10-26-07-51-55.gh-issue-98703.0hW773.rst
M Lib/asyncio/proactor_events.py

diff --git a/Lib/asyncio/proactor_events.py b/Lib/asyncio/proactor_events.py
index 2685a3376cfd..c6aab408fc74 100644
--- a/Lib/asyncio/proactor_events.py
+++ b/Lib/asyncio/proactor_events.py
@@ -152,6 +152,8 @@ def _force_close(self, exc):
         self._loop.call_soon(self._call_connection_lost, exc)
 
     def _call_connection_lost(self, exc):
+        if self._called_connection_lost:
+            return
         try:
             self._protocol.connection_lost(exc)
         finally:
diff --git a/Misc/NEWS.d/next/Library/2022-10-26-07-51-55.gh-issue-98703.0hW773.rst b/Misc/NEWS.d/next/Library/2022-10-26-07-51-55.gh-issue-98703.0hW773.rst
new file mode 100644
index 000000000000..3107519a8714
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2022-10-26-07-51-55.gh-issue-98703.0hW773.rst
@@ -0,0 +1,2 @@
+Fix :meth:`asyncio.StreamWriter.drain` to call ``protocol.connection_lost``
+callback only once on Windows.



More information about the Python-checkins mailing list