Issue 31235: test_logging: ResourceWarning: unclosed <socket.socket ...> (original) (raw)

Sometimes, running test_logging emits such warning:

ResourceWarning: unclosed <socket.socket fd=6, family=AddressFamily.AF_INET, type=536870913, proto=0, laddr=('127.0.0.1', 31191), raddr=('127.0.0.1', 31192)>

I'm not sure where it does come from.

See also bpo-30830 (test_logging leaks dangling threads on FreeBSD).

Traceback from tracemalloc:

10-STABLE-amd64% ./python -X tracemalloc=10 -m test -v test_logging --fail-env-changed

(...)

/usr/home/haypo/cpython/Lib/test/support/init.py:1515: ResourceWarning: unclosed <socket.socket fd=6, family=AddressFamily.AF_INET, type=536870913, proto=0, laddr=('127.0.0.1', 26785), raddr=('127.0.0.1', 26788)> gc.collect() Object allocated at (most recent call first): File "/usr/home/haypo/cpython/Lib/socket.py", lineno 210 sock = socket(self.family, type, self.proto, fileno=fd) File "/usr/home/haypo/cpython/Lib/asyncore.py", lineno 348 conn, addr = self.socket.accept() File "/usr/home/haypo/cpython/Lib/asyncore.py", lineno 492 pair = self.accept() File "/usr/home/haypo/cpython/Lib/asyncore.py", lineno 417 self.handle_accept() File "/usr/home/haypo/cpython/Lib/asyncore.py", lineno 83 obj.handle_read_event() File "/usr/home/haypo/cpython/Lib/asyncore.py", lineno 150 read(obj) File "/usr/home/haypo/cpython/Lib/asyncore.py", lineno 203 poll_fun(timeout, map) File "/usr/home/haypo/cpython/Lib/test/test_logging.py", lineno 782 asyncore.loop(poll_interval, map=self._map) File "/usr/home/haypo/cpython/Lib/threading.py", lineno 865 self._target(*self._args, **self._kwargs) File "/usr/home/haypo/cpython/Lib/threading.py", lineno 917 self.run()

So it seems like the socket was created in TestSMTPServer.serve_forever() of test_logging, which is used by SMTPHandlerTest.test_basic().