Repository navigation
Closed
Closed
Copy link
Labels
testsTests in the Lib/test dirTests in the Lib/test dirtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Build: https://buildbot.python.org/#/builders/2056/builds/483
Would it be possible to skip the test on a network error? Or would it defeat the purpose of the test?
test_imaplib_timeout_functionality_test (test.test_imaplib.NewIMAPSSLTests.test_imaplib_timeout_functionality_test) ... SENT: b'* OK IMAP4rev1'
GOT: b'JKNP0 CAPABILITY'
SENT: b'* CAPABILITY IMAP4rev1'
SENT: b'JKNP0 OK CAPABILITY completed'
ERROR
======================================================================
ERROR: test_imaplib_timeout_functionality_test (test.test_imaplib.NewIMAPSSLTests.test_imaplib_timeout_functionality_test)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/buildbot/buildarea/3.15.opsec-fbsd14.refleak/build/Lib/test/test_imaplib.py", line 745, in test_imaplib_timeout_functionality_test
client = self.imap_class("localhost", addr, timeout=0.001)
File "/home/buildbot/buildarea/3.15.opsec-fbsd14.refleak/build/Lib/imaplib.py", line 1772, in __init__
IMAP4.__init__(self, host, port, timeout)
~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/buildbot/buildarea/3.15.opsec-fbsd14.refleak/build/Lib/imaplib.py", line 217, in __init__
self.open(host, port, timeout)
~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^
File "/home/buildbot/buildarea/3.15.opsec-fbsd14.refleak/build/Lib/imaplib.py", line 1785, in open
IMAP4.open(self, host, port, timeout)
~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/buildbot/buildarea/3.15.opsec-fbsd14.refleak/build/Lib/imaplib.py", line 331, in open
self.sock = self._create_socket(timeout)
~~~~~~~~~~~~~~~~~~~^^^^^^^^^
File "/home/buildbot/buildarea/3.15.opsec-fbsd14.refleak/build/Lib/imaplib.py", line 1775, in _create_socket
sock = IMAP4._create_socket(self, timeout)
File "/home/buildbot/buildarea/3.15.opsec-fbsd14.refleak/build/Lib/imaplib.py", line 320, in _create_socket
return socket.create_connection(address, timeout)
~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^
File "/home/buildbot/buildarea/3.15.opsec-fbsd14.refleak/build/Lib/socket.py", line 887, in create_connection
raise exceptions[0]
File "/home/buildbot/buildarea/3.15.opsec-fbsd14.refleak/build/Lib/socket.py", line 872, in create_connection
sock.connect(sa)
~~~~~~~~~~~~^^^^
ConnectionRefusedError: [Errno 61] Connection refused
Linked PRs
Metadata
Metadata
Assignees
Labels
testsTests in the Lib/test dirTests in the Lib/test dirtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Activity
NekoAsakura commentedon Nov 4, 2026
Well, the test connects to the wrong host. On FreeBSD:
We could fix instead of skip.
vstinner commentedon Nov 5, 2026
Can you elaborate? Which host is used? I would expect "localhost" to be resolved to 127.0.0.1 (IPv4) or ::1 (IPv6), the local loopback. So it should just work, no?
vstinner commentedon Nov 5, 2026
I failed to reproduce the issue on FreeBSD:
NekoAsakura commentedon Nov 5, 2026
That's the problem. The server only listens on
127.0.0.1. If that connect takes over 1 ms, theTimeoutErroris dropped (L890) and::1is tried next, which is refused.cpython/Lib/socket.py
Lines 874 to 891 in f8e65ee
To reproduce, you need to add some latency on ipv4 loopback with
tc netem.vstinner commentedon Nov 5, 2026
Wait. What is this 1 ms timeout? Why not using support.LOOPBACK_TIMEOUT (10 sec by default).
NekoAsakura commentedon Nov 5, 2026
Because the test wants a
TimeoutError(by set a very short timeout); the problem is that it gets dropped.cpython/Lib/test/test_imaplib.py
Lines 897 to 906 in f8e65ee
NekoAsakura commentedon Nov 5, 2026
Let me spell out the logic. The test expects a
TimeoutError. The handler sleeps 1s before the greeting and the client waits 1 ms, so normally the connect to127.0.0.1succeeds and the timeout hits while reading the greeting.On a busy machine the connect itself can take over 1 ms. With
localhost,create_connection()drops thatTimeoutError, moves on to::1where nothing listens, and reports only the last error, which isConnectionRefusedError. Withserver.server_addressthere is a single address, so a slow connect raisesTimeoutErroras well.gh-161336: fix host mismatch in the `test_imaplib` (#161349)
vstinner commentedon Nov 5, 2026
Oh. That's subtle: create_connection() catches OSError and moves to the next IP address, and TimeoutError is a OSError sub-class. I see. I merged your fix.
[3.14] gh-161336: fix host mismatch in the `test_imaplib` (GH-161349) (…
[3.15] gh-161336: fix host mismatch in the `test_imaplib` (GH-161349) (…