Skip to content

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

@aisk

Description

@aisk

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:

gai_results = socket.getaddrinfo(*localaddr,
type=socket.SOCK_STREAM)
self.create_socket(gai_results[0][0], gai_results[0][1])

--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

Metadata

Metadata

Assignees

No one assigned

    Labels

    testsTests in the Lib/test dirtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions