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.

ResourceWarning: unclosed ssl.SSLSocket

See original GitHub issue

For some reason I’m getting a ResourceWarning about a unclosed socket, even when I’m specifically closing the socket myself. See testcase below:

python3 -munittest discover
import sys
import boto3
import unittest

BUCKET = ''
KEY = ''


def give_it_to_me():
    client = boto3.client('s3')
    obj = client.get_object(Bucket=BUCKET, Key=KEY)
    try:
        yield from iter(lambda: obj['Body'].read(1024), b'')
    finally:
        print('Im closing it!', file=sys.stderr, flush=True)
        obj['Body'].close()


class TestSomeShit(unittest.TestCase):
    def test_it(self):
        res = give_it_to_me()
        for chunk in res:
            pass
        print('Done', file=sys.stderr, flush=True)

Fill in any BUCKET and KEY to see the problem. Attaching my output below:

Im closing it!
test.py:22: ResourceWarning: unclosed <ssl.SSLSocket fd=7, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6, laddr=('...', 55498), raddr=('...', 443)>
  for chunk in res:
Done
.
----------------------------------------------------------------------
Ran 1 test in 0.696s

OK

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:82
  • Comments:52 (9 by maintainers)

github_iconTop GitHub Comments

213reactions
nchammascommented, Jan 7, 2018

@student-t

So no fix? Warning is still important. boto3 developers are lazy.

Don’t use this kind of language, especially not on an open source project where the developers owe you nothing and you are getting their work for free.

If this issue is so important to you that you can’t wait for a fix to be submitted and merged in, then fork the project and fix it yourself, and spare us all this kind of low quality whining.

135reactions
scchesscommented, Jan 7, 2018

So no fix? Warning is still important. boto3 developers are lazy.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ResourceWarning unclosed socket in Python 3 Unit Test
I'm modifying some code to be compatible between Python 2 and Python 3 , but have observed a warning in unit test output....
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 >
Issue 43885: ResourceWarning: unclosed <ssl.SSLSocket ...
... /home/heimes/dev/python/cpython/Lib/test/support/threading_helper.py:209: ResourceWarning: unclosed <ssl.SSLSocket fd=5, family=AF_INET, ...
Read more >
ResourceWarning unclosed socket in Python 3 Unit Test
Python – ResourceWarning unclosed socket in Python 3 Unit Test. pythonpython-3.xpython-unittestsockets. I'm modifying some code to be compatible between ...
Read more >
Still observing close file warnings with overcloud commands
ret_value = super(OpenStackShell, self).run_subcommand(argv) sys:1: ResourceWarning: unclosed <ssl.SSLSocket fd=4, family=AddressFamily.
Read more >

github_iconTop Related Medium Post

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