mirror of
https://github.com/python/cpython.git
synced 2025-08-23 02:04:56 +00:00
[3.12] gh-126876: Fix socket internal_select() for large timeout (GH-126968) (#127003)
gh-126876: Fix socket internal_select() for large timeout (GH-126968)
If the timeout is larger than INT_MAX, replace it with INT_MAX, in
the poll() code path.
Add an unit test.
(cherry picked from commit b3687ad454
)
Co-authored-by: Victor Stinner <vstinner@python.org>
This commit is contained in:
parent
c40656eeff
commit
b49e902b81
2 changed files with 34 additions and 1 deletions
|
@ -5059,6 +5059,36 @@ class NonBlockingTCPTests(ThreadedTCPSocketTest):
|
|||
# send data: recv() will no longer block
|
||||
self.cli.sendall(MSG)
|
||||
|
||||
@support.cpython_only
|
||||
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).
|
||||
import _testcapi
|
||||
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
|
||||
import _testcapi
|
||||
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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue