Skip to content

test_asyncio.test_events failed with "env changed" on AMD64 FreeBSD14 3.14: Warning -- Unraisable exception (...) ResourceWarning: unclosed <socket...> #159123

Closed

Description

@vstinner

AMD64 FreeBSD14 3.14: https://buildbot.python.org/#/builders/1740/builds/1746

test_create_server_reuse_port (test.test_asyncio.test_events.PollEventLoopTests.test_create_server_reuse_port) ... ok
test_create_server_sock (test.test_asyncio.test_events.PollEventLoopTests.test_create_server_sock) ... ok
test_create_server_ssl (test.test_asyncio.test_events.PollEventLoopTests.test_create_server_ssl) ... ok
test_create_server_ssl_match_failed (test.test_asyncio.test_events.PollEventLoopTests.test_create_server_ssl_match_failed) ... Warning -- Unraisable exception
Exception ignored while finalizing socket <socket.socket fd=7, family=2, type=1, proto=6, laddr=('127.0.0.1', 18337), raddr=('127.0.0.1', 39292)>:
Traceback (most recent call last):
  File "/home/buildbot/buildarea/3.14.opsec-fbsd14/build/Lib/test/support/__init__.py", line 861, in gc_collect
    gc.collect()
ResourceWarning: unclosed <socket.socket fd=7, family=2, type=1, proto=6, laddr=('127.0.0.1', 18337), raddr=('127.0.0.1', 39292)>
Warning -- Unraisable exception
Exception ignored while calling deallocator <function _SelectorTransport.__del__ at 0xafcf2b8bdd0>:
Traceback (most recent call last):
  File "/home/buildbot/buildarea/3.14.opsec-fbsd14/build/Lib/asyncio/selector_events.py", line 875, in __del__
    _warn(f"unclosed transport {self!r}", ResourceWarning, source=self)
ResourceWarning: unclosed transport <_SelectorSocketTransport closing fd=7>
ok
test_create_server_ssl_verified (test.test_asyncio.test_events.PollEventLoopTests.test_create_server_ssl_verified) ... ok
test_create_server_ssl_verify_failed (test.test_asyncio.test_events.PollEventLoopTests.test_create_server_ssl_verify_failed) ... Warning -- Unraisable exception
Exception ignored while finalizing socket <socket.socket fd=7, family=2, type=1, proto=6, laddr=('127.0.0.1', 54585), raddr=('127.0.0.1', 54281)>:
Traceback (most recent call last):
  File "/home/buildbot/buildarea/3.14.opsec-fbsd14/build/Lib/test/support/__init__.py", line 861, in gc_collect
    gc.collect()
ResourceWarning: unclosed <socket.socket fd=7, family=2, type=1, proto=6, laddr=('127.0.0.1', 54585), raddr=('127.0.0.1', 54281)>
Warning -- Unraisable exception
Exception ignored while calling deallocator <function _SelectorTransport.__del__ at 0xafcf2b8bdd0>:
Traceback (most recent call last):
  File "/home/buildbot/buildarea/3.14.opsec-fbsd14/build/Lib/asyncio/selector_events.py", line 875, in __del__
    _warn(f"unclosed transport {self!r}", ResourceWarning, source=self)
ResourceWarning: unclosed transport <_SelectorSocketTransport closing fd=7>
ok
test_create_server_trsock (test.test_asyncio.test_events.PollEventLoopTests.test_create_server_trsock) ... ok
test_create_ssl_connection (test.test_asyncio.test_events.PollEventLoopTests.test_create_ssl_connection) ... ok
test_create_ssl_unix_connection (test.test_asyncio.test_events.PollEventLoopTests.test_create_ssl_unix_connection) ... ok
test_create_unix_connection (test.test_asyncio.test_events.PollEventLoopTests.test_create_unix_connection) ... ok

Linked PRs

Activity

  1. vstinner commented on Oct 21, 2026

    @vstinner
    MemberAuthor

    At least two test_asyncio.test_events tests are logging the unclosed <socket.socket ...> warning:

    • test_create_server_ssl_match_failed()
    • test_create_server_ssl_verify_failed()
  2. vstinner commented on Oct 21, 2026

    @vstinner
    MemberAuthor

    I tried but failed so far to reproduce the issue on my FreeBSD 14 VM. I ran two commands in parallel (in tmux):

    • ./python -u -X tracemalloc=10 -m test --fail-env-changed test_asyncio.test_events -v -F 2>&1|tee log
    • ./python -m test --fail-env-changed test_asyncio.test_events -W -j6 -F

    I ran these commands for 10 minutes.

  3. vstinner commented on Oct 21, 2026

    @vstinner
    MemberAuthor

    Aha, the issue was also seen on AMD64 FreeBSD15 3.14: https://buildbot.python.org/#/builders/1749/builds/1904

    test_create_server_ssl_verify_failed (test.test_asyncio.test_events.KqueueEventLoopTests.test_create_server_ssl_verify_failed) ... Warning -- Unraisable exception
    Exception ignored while finalizing socket <socket.socket fd=8, family=2, type=1, proto=6, laddr=('127.0.0.1', 35762), raddr=('127.0.0.1', 29066)>:
    Traceback (most recent call last):
      File "/home/buildbot/buildarea/3.14.opsec-fbsd15/build/Lib/test/support/__init__.py", line 861, in gc_collect
        gc.collect()
    ResourceWarning: unclosed <socket.socket fd=8, family=2, type=1, proto=6, laddr=('127.0.0.1', 35762), raddr=('127.0.0.1', 29066)>
    Warning -- Unraisable exception
    Exception ignored while calling deallocator <function _SelectorTransport.__del__ at 0x1dcee15f6c90>:
    Traceback (most recent call last):
      File "/home/buildbot/buildarea/3.14.opsec-fbsd15/build/Lib/asyncio/selector_events.py", line 875, in __del__
        _warn(f"unclosed transport {self!r}", ResourceWarning, source=self)
    ResourceWarning: unclosed transport <_SelectorSocketTransport closing fd=8>
    ok
    

    and

    test_create_server_ssl_match_failed (test.test_asyncio.test_events.KqueueEventLoopTests.test_create_server_ssl_match_failed) ... Warning -- Unraisable exception
    Exception ignored while finalizing socket <socket.socket fd=9, family=2, type=1, proto=6, laddr=('127.0.0.1', 47622), raddr=('127.0.0.1', 54655)>:
    Traceback (most recent call last):
      File "/home/buildbot/buildarea/3.14.opsec-fbsd15/build/Lib/test/support/__init__.py", line 861, in gc_collect
        gc.collect()
    ResourceWarning: unclosed <socket.socket fd=9, family=2, type=1, proto=6, laddr=('127.0.0.1', 47622), raddr=('127.0.0.1', 54655)>
    Warning -- Unraisable exception
    Exception ignored while calling deallocator <function _SelectorTransport.__del__ at 0x243c211f5190>:
    Traceback (most recent call last):
      File "/home/buildbot/buildarea/3.14.opsec-fbsd15/build/Lib/asyncio/selector_events.py", line 875, in __del__
        _warn(f"unclosed transport {self!r}", ResourceWarning, source=self)
    ResourceWarning: unclosed transport <_SelectorSocketTransport closing fd=9>
    ok
    
  4. vstinner commented on Oct 21, 2026

    @vstinner
    MemberAuthor

    @kumaraditya303: Would you mind to have a look at these 2 failing asyncio tests?

    How can I reproduce these failures? Any idea on how to fix tests?

    test_create_server_ssl_verify_failed() code is suspicious: it overrides call_exception_handler() and makes the logger quit. Why is it needed?

            # no CA loaded
            f_c = self.loop.create_connection(MyProto, host, port,
                                              ssl=sslcontext_client)
            with mock.patch.object(self.loop, 'call_exception_handler'):
                with test_utils.disable_logger():
                    with self.assertRaisesRegex(ssl.SSLError,
                                                '(?i)certificate.verify.failed'):
                        self.loop.run_until_complete(f_c)
    
                # execute the loop to log the connection error
                test_utils.run_briefly(self.loop)
  5. vstinner commented on Oct 22, 2026

    @vstinner
    MemberAuthor

    See also #160206 (test_ssl).

  6. kumaraditya303 commented on Oct 22, 2026

    @kumaraditya303
    Contributor

    There is a race in test which is causing this, I created #160209 to fix this.

  7. added a commit that references this issue on Oct 22, 2026
  8. moved this from Todo to Done in asyncioon Oct 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    • Status
      Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions