question-mark
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 cheroot_only.py 
/usr/lib/python3.8/threading.py:870: 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/threading.py", lineno 932
    self.run()
  File "/usr/lib/python3.8/threading.py", lineno 870
    self._target(*self._args, **self._kwargs)
  File "/home/sander/.local/lib/python3.8/site-packages/cheroot/ssl/builtin.py", lineno 68
    target=lambda: context.wrap_socket(
  File "/usr/lib/python3.8/ssl.py", lineno 500
    return self.sslsocket_class._create(
  File "/usr/lib/python3.8/ssl.py", lineno 1003
    self = cls.__new__(cls, **kwargs)
/home/sander/.local/lib/python3.8/site-packages/cheroot/ssl/builtin.py:75: 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/builtin.py", lineno 198
    _parse_cert(certificate, private_key, self.certificate_chain),
  File "/home/sander/.local/lib/python3.8/site-packages/cheroot/ssl/builtin.py", lineno 94
    return _loopback_for_cert(certificate, private_key, certificate_chain)
  File "/home/sander/.local/lib/python3.8/site-packages/cheroot/ssl/builtin.py", lineno 75
    return context.wrap_socket(
  File "/usr/lib/python3.8/ssl.py", lineno 500
    return self.sslsocket_class._create(
  File "/usr/lib/python3.8/ssl.py", lineno 1003
    self = cls.__new__(cls, **kwargs)

with this code:

#!/usr/bin/python3

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 = '0.0.0.0', 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')

server.start()

💡 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 https://github.com/sabnzbd/sabnzbd/issues/1489

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
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.

1reaction
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 Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found