python / cpython

The Python programming language
https://www.python.org/
Other
60.95k stars 29.42k forks source link

Some tests in test_smtplib and test_logging failed when Python is configured with `--disable-ipv6` #121275

Open aisk opened 1 week ago

aisk commented 1 week ago

Bug report

Bug description:

There is a error sample:

ERROR: test_basic (test.test_logging.SMTPHandlerTest.test_basic)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/asaka/Codes/cpython/Lib/test/test_logging.py", line 1121, in test_basic
    server = TestSMTPServer((socket_helper.HOST, 0), self.process_message, 0.001,
                            sockmap)
  File "/home/asaka/Codes/cpython/Lib/test/test_logging.py", line 882, in __init__
    smtpd.SMTPServer.__init__(self, addr, None, map=sockmap,
    ~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                              decode_data=True)
                              ^^^^^^^^^^^^^^^^^
  File "/home/asaka/Codes/cpython/Lib/test/support/smtpd.py", line 641, in __init__
    self.bind(localaddr)
    ~~~~~~~~~^^^^^^^^^^^
  File "/home/asaka/Codes/cpython/Lib/test/support/asyncore.py", line 332, in bind
    return self.socket.bind(addr)
           ~~~~~~~~~~~~~~~~^^^^^^
OSError: bind(): bad family

This is caused by SMTPServer is using socket.getaddrinfo to get the socket family, which also include IPv6 result even if IPv6 support is disabled, and it's value will be used to socket.bind:

https://github.com/python/cpython/blob/6343486eb60ac5a9e15402a592298259c5afdee1/Lib/test/support/smtpd.py#L636-L638

--disable-ipv6 must be specified when --with-thread-sanitizer is specified on my machine (Arch with Clang17), so I think it's better to fix it although --disable-ipv6 is not widely used.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

vstinner commented 5 days ago

--disable-ipv6 must be specified when --with-thread-sanitizer is specified on my machine (Arch with Clang17)

Would you mind to elaborate?

aisk commented 4 days ago

I didn't dig too much, but ./configure --with-thread-sanitizer on my machine will cause a:

configure: error: You must get working getaddrinfo() function or pass the "--disable-ipv6" option to configure.

Maybe it's caused by https://github.com/google/sanitizers/issues/1592

vstinner commented 2 days ago

Do you want to work on a PR to skip some tests if IPv6 is disabled?

aisk commented 2 days ago

Do you want to work on a PR to skip some tests if IPv6 is disabled?

Working on it.