summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2024-11-19 08:08:42 (GMT)
committerGitHub <noreply@github.com>2024-11-19 08:08:42 (GMT)
commitb3687ad454c4ac54c8599a10f3ace8a13ca48915 (patch)
treec11880ac43bd1d01d386c16fe1af8f3fae793b32 /Lib
parentd6b3e78504b3168c432b20002dbcf8ec9a435e61 (diff)
downloadcpython-b3687ad454c4ac54c8599a10f3ace8a13ca48915.zip
cpython-b3687ad454c4ac54c8599a10f3ace8a13ca48915.tar.gz
cpython-b3687ad454c4ac54c8599a10f3ace8a13ca48915.tar.bz2
gh-126876: Fix socket internal_select() for large timeout (#126968)
If the timeout is larger than INT_MAX, replace it with INT_MAX, in the poll() code path. Add an unit test.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_socket.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py
index dc8a4a4..7b3914f 100644
--- a/Lib/test/test_socket.py
+++ b/Lib/test/test_socket.py
@@ -5132,6 +5132,33 @@ class NonBlockingTCPTests(ThreadedTCPSocketTest):
# send data: recv() will no longer block
self.cli.sendall(MSG)
+ def testLargeTimeout(self):
+ # gh-126876: Check that a timeout larger than INT_MAX is replaced with
+ # INT_MAX in the poll() code path. The following assertion must not
+ # fail: assert(INT_MIN <= ms && ms <= INT_MAX).
+ large_timeout = _testcapi.INT_MAX + 1
+
+ # test recv() with large timeout
+ conn, addr = self.serv.accept()
+ self.addCleanup(conn.close)
+ try:
+ conn.settimeout(large_timeout)
+ except OverflowError:
+ # On Windows, settimeout() fails with OverflowError, whereas
+ # we want to test recv(). Just give up silently.
+ return
+ msg = conn.recv(len(MSG))
+
+ def _testLargeTimeout(self):
+ # test sendall() with large timeout
+ large_timeout = _testcapi.INT_MAX + 1
+ self.cli.connect((HOST, self.port))
+ try:
+ self.cli.settimeout(large_timeout)
+ except OverflowError:
+ return
+ self.cli.sendall(MSG)
+
class FileObjectClassTestCase(SocketConnectedTest):
"""Unit tests for the object returned by socket.makefile()