[Python-checkins] gh-98174: Handle EPROTOTYPE under macOS in test_sendfile_fallback_close_peer_in_the_middle_of_receiving (GH-98316)

miss-islington webhook-mailer at python.org
Mon Oct 17 12:13:46 EDT 2022


https://github.com/python/cpython/commit/3adf23471ee951a435f2ffa336a52bc6800a209a
commit: 3adf23471ee951a435f2ffa336a52bc6800a209a
branch: 3.10
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-17T09:13:37-07:00
summary:

gh-98174: Handle EPROTOTYPE under macOS in test_sendfile_fallback_close_peer_in_the_middle_of_receiving (GH-98316)


Co-authored-by: Nikita Sobolev <mail at sobolevn.me>
(cherry picked from commit 3e82ad05b18d004e4d01fdb643344d6a2bf11900)

Co-authored-by: fancidev <fancidev at gmail.com>

files:
M Lib/test/test_asyncio/test_sendfile.py

diff --git a/Lib/test/test_asyncio/test_sendfile.py b/Lib/test/test_asyncio/test_sendfile.py
index effca6644c06..aaaad9df8eb8 100644
--- a/Lib/test/test_asyncio/test_sendfile.py
+++ b/Lib/test/test_asyncio/test_sendfile.py
@@ -1,6 +1,7 @@
 """Tests for sendfile functionality."""
 
 import asyncio
+import errno
 import os
 import socket
 import sys
@@ -484,8 +485,17 @@ def sendfile_native(transp, file, offset, count):
 
         srv_proto, cli_proto = self.prepare_sendfile(close_after=1024)
         with self.assertRaises(ConnectionError):
-            self.run_loop(
-                self.loop.sendfile(cli_proto.transport, self.file))
+            try:
+                self.run_loop(
+                    self.loop.sendfile(cli_proto.transport, self.file))
+            except OSError as e:
+                # macOS may raise OSError of EPROTOTYPE when writing to a
+                # socket that is in the process of closing down.
+                if e.errno == errno.EPROTOTYPE and sys.platform == "darwin":
+                    raise ConnectionError
+                else:
+                    raise
+
         self.run_loop(srv_proto.done)
 
         self.assertTrue(1024 <= srv_proto.nbytes < len(self.DATA),



More information about the Python-checkins mailing list