classification
Title: test_logging: ResourceWarning: unclosed
Type: resource usage Stage: resolved
Components: Versions: Python 3.7, Python 3.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: vstinner
Priority: normal Keywords:

Created on 2017-08-18 21:42 by vstinner, last changed 2017-08-18 23:11 by vstinner. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 3147 merged vstinner, 2017-08-18 22:07
PR 3149 merged vstinner, 2017-08-18 22:54
Messages (5)
msg300534 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-08-18 21:42
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).
msg300540 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-08-18 22:06
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().
msg300542 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-08-18 22:34
New changeset a7719e27b3cad0f2b86cb932a76cbe55c541b02e by Victor Stinner in branch 'master':
bpo-31235: Fix ResourceWarning in test_logging (#3147)
https://github.com/python/cpython/commit/a7719e27b3cad0f2b86cb932a76cbe55c541b02e
msg300546 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-08-18 22:57
Python 2.7 is not affected: it doesn't have SMTPHandlerTest.
msg300549 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-08-18 23:11
New changeset 3e866dfaecaa4eb8f98c12782d2488f681225c37 by Victor Stinner in branch '3.6':
bpo-31235: Fix ResourceWarning in test_logging (#3147) (#3149)
https://github.com/python/cpython/commit/3e866dfaecaa4eb8f98c12782d2488f681225c37
History
Date User Action Args
2017-08-18 23:11:55vstinnersetstatus: open -> closed
resolution: fixed
stage: resolved
2017-08-18 23:11:46vstinnersetmessages: + msg300549
2017-08-18 22:57:48vstinnersetmessages: + msg300546
versions: + Python 3.6
2017-08-18 22:54:41vstinnersetpull_requests: + pull_request3183
2017-08-18 22:34:02vstinnersetmessages: + msg300542
2017-08-18 22:07:50vstinnersetpull_requests: + pull_request3182
2017-08-18 22:06:30vstinnersetmessages: + msg300540
2017-08-18 21:42:26vstinnercreate