Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. Itย collects links to all the places you might be looking at while hunting down a tough bug.

And, if youโ€™re still stuck at the end, weโ€™re happy to hop on a call to see how we can help out.

with "-X dev": ResourceWarning: unclosed <ssl.SSLSocket fd=4 ...

See original GitHub issue

โ“ Iโ€™m submitting a โ€ฆ

  • ๐Ÿž bug report
  • ๐Ÿฃ feature request
  • โ“ question about the decisions made in the repository

๐Ÿž Describe the bug. What is the current behavior? With python3 -X dev -X tracemalloc=5 on cheroot code with SSL, python gives a ResourceWarning

โ“ What is the motivation / use case for changing the behavior?

A python ResourceWarning is an good indication code can be improved: itโ€™s not closing a resource. It generates warnings in other code (SABnzbd) this is using cherrypy / cheroot (when running that code with -X dev), which makes cleaning up own code more difficult.

๐Ÿ’ก To Reproduce

$ python3 -X dev -X tracemalloc=5 
/usr/lib/python3.8/ ResourceWarning: unclosed <ssl.SSLSocket fd=4, family=AddressFamily.AF_UNIX, type=SocketKind.SOCK_STREAM, proto=0>
  self._target(*self._args, **self._kwargs)
Object allocated at (most recent call last):
  File "/usr/lib/python3.8/", lineno 932
  File "/usr/lib/python3.8/", lineno 870
    self._target(*self._args, **self._kwargs)
  File "/home/sander/.local/lib/python3.8/site-packages/cheroot/ssl/", lineno 68
    target=lambda: context.wrap_socket(
  File "/usr/lib/python3.8/", lineno 500
    return self.sslsocket_class._create(
  File "/usr/lib/python3.8/", lineno 1003
    self = cls.__new__(cls, **kwargs)
/home/sander/.local/lib/python3.8/site-packages/cheroot/ssl/ ResourceWarning: unclosed <ssl.SSLSocket fd=3, family=AddressFamily.AF_UNIX, type=SocketKind.SOCK_STREAM, proto=0>
  return context.wrap_socket(
Object allocated at (most recent call last):
  File "/home/sander/.local/lib/python3.8/site-packages/cheroot/ssl/", lineno 198
    _parse_cert(certificate, private_key, self.certificate_chain),
  File "/home/sander/.local/lib/python3.8/site-packages/cheroot/ssl/", lineno 94
    return _loopback_for_cert(certificate, private_key, certificate_chain)
  File "/home/sander/.local/lib/python3.8/site-packages/cheroot/ssl/", lineno 75
    return context.wrap_socket(
  File "/usr/lib/python3.8/", lineno 500
    return self.sslsocket_class._create(
  File "/usr/lib/python3.8/", lineno 1003
    self = cls.__new__(cls, **kwargs)

with this code:


from cheroot import wsgi
def my_crazy_app(environ, start_response):
    status = '200 OK'
    response_headers = [('Content-type','text/plain')]
    start_response(status, response_headers)
    return [b'Hello world!']
addr = '', 8070
server = wsgi.Server(addr, my_crazy_app)

# the SSL stuff:
from cheroot.server import get_ssl_adapter_class
server.ssl_adapter = get_ssl_adapter_class(name='builtin')('./server.cert', './server.key')


๐Ÿ’ก Expected behavior No ResourceWarning

๐Ÿ“‹ Details See above

๐Ÿ“‹ Environment

  • Cheroot version: 8.3.0
  • CherryPy version: 18.5.0
  • Python version: 3.8
  • OS: Ubuntu 20.04
  • Browser: not involved to get ResourceWarning

๐Ÿ“‹ Additional context

Related to

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:16 (16 by maintainers)

github_iconTop GitHub Comments

webknjazcommented, Jun 6, 2020

@mxii-ca @sanderjo yeah, I know that Python tracks resources like that, and even though this leakage is minor, Iโ€™d like to have it closed correctly. So a PR would be appreciated.

webknjazcommented, Jun 6, 2020

Mind updating the issue at the top with the new repro?

Read more comments on GitHub >

github_iconTop Results From Across the Web

ResourceWarning unclosed socket in Python 3 Unit Test
Is there a better / correct way to manage the session so that it gets explicitly closed and not rely on __del__() to...
Read more >
Issue 43885: ResourceWarning: unclosed <ssl.SSLSocket ...
This issue tracker has been migrated to GitHub, and is currently read-only. For more information, see the GitHub FAQs in the Python's Developer...
Read more >
sys:1: ResourceWarning: unclosed <ssl.SSLSocket fd=4 ...
Description of problem: See Resource warning on various openstack commands: A couple seen on: - openstack overcloud node introspect --all-manageableย ...
Read more >
Incomprehensible warnings in log files - Tryton Discussion
... ResourceWarning: unclosed <socket.socket fd=12, family=Addresโ€ฆ ... Who is the developer of the ldap_authentication module?
Read more >
Does anyone else ever get an odd warning like this when ...
sys:1: ResourceWarning: unclosed <ssl.SSLSocket fd=5, family=AddressFamily.AF_INET, type=2049, proto=6, laddr=(some address', 55332),ย ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found