aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2024-06-01 18:27:54 +0200
committerGitHub <noreply@github.com>2024-06-01 16:27:54 +0000
commit0ea77d49cc5380b2fe294fb7cc3754df7ac08419 (patch)
treebd965a6070c7327bc6164c0cbcf570befcf9a549
parent[3.13] Revert "[3.13] gh-69214: Fix fcntl.ioctl() request type (GH-119498) (â... (diff)
downloadcpython-0ea77d49cc5380b2fe294fb7cc3754df7ac08419.tar.gz
cpython-0ea77d49cc5380b2fe294fb7cc3754df7ac08419.tar.bz2
cpython-0ea77d49cc5380b2fe294fb7cc3754df7ac08419.zip
[3.13] gh-113892: Add a extra check to `ProactorEventLoop.sock_connect` to ensure that the given socket is in non-blocking mode (GH-119519) (#119912)
(cherry picked from commit cf3bba3f0671d2c9fee099e3ab0f78b98b176131) Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru>
-rw-r--r--Lib/asyncio/proactor_events.py2
-rw-r--r--Lib/test/test_asyncio/test_proactor_events.py9
-rw-r--r--Misc/NEWS.d/next/Library/2024-05-24-21-54-55.gh-issue-113892.JKDFqq.rst3
3 files changed, 12 insertions, 2 deletions
diff --git a/Lib/asyncio/proactor_events.py b/Lib/asyncio/proactor_events.py
index 397a8cda757..7eb55bd63dd 100644
--- a/Lib/asyncio/proactor_events.py
+++ b/Lib/asyncio/proactor_events.py
@@ -721,6 +721,8 @@ class BaseProactorEventLoop(base_events.BaseEventLoop):
return await self._proactor.sendto(sock, data, 0, address)
async def sock_connect(self, sock, address):
+ if self._debug and sock.gettimeout() != 0:
+ raise ValueError("the socket must be non-blocking")
return await self._proactor.connect(sock, address)
async def sock_accept(self, sock):
diff --git a/Lib/test/test_asyncio/test_proactor_events.py b/Lib/test/test_asyncio/test_proactor_events.py
index fcaa2f6ade2..4b3d551dd7b 100644
--- a/Lib/test/test_asyncio/test_proactor_events.py
+++ b/Lib/test/test_asyncio/test_proactor_events.py
@@ -1018,9 +1018,9 @@ class ProactorEventLoopUnixSockSendfileTests(test_utils.TestCase):
self.addCleanup(self.file.close)
super().setUp()
- def make_socket(self, cleanup=True):
+ def make_socket(self, cleanup=True, blocking=False):
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- sock.setblocking(False)
+ sock.setblocking(blocking)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 1024)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 1024)
if cleanup:
@@ -1082,6 +1082,11 @@ class ProactorEventLoopUnixSockSendfileTests(test_utils.TestCase):
0, None))
self.assertEqual(self.file.tell(), 0)
+ def test_blocking_socket(self):
+ self.loop.set_debug(True)
+ sock = self.make_socket(blocking=True)
+ with self.assertRaisesRegex(ValueError, "must be non-blocking"):
+ self.run_loop(self.loop.sock_sendfile(sock, self.file))
if __name__ == '__main__':
unittest.main()
diff --git a/Misc/NEWS.d/next/Library/2024-05-24-21-54-55.gh-issue-113892.JKDFqq.rst b/Misc/NEWS.d/next/Library/2024-05-24-21-54-55.gh-issue-113892.JKDFqq.rst
new file mode 100644
index 00000000000..639d5abe878
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2024-05-24-21-54-55.gh-issue-113892.JKDFqq.rst
@@ -0,0 +1,3 @@
+Now, the method ``sock_connect`` of :class:`asyncio.ProactorEventLoop`
+raises a :exc:`ValueError` if given socket is not in
+non-blocking mode, as well as in other loop implementations.