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 fd=20, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6, laddr=('10.1.0.62', 52098), raddr=('52.239.140.10', 443)>

See original GitHub issue
  • azure-storage-blob:
  • 12.5.0:
  • Linux 39a68fd14e65 4.19.76-linuxkit #1 SMP Tue May 26 11:42:35 UTC 2020 x86_64 GNU/Linux:
  • Python 3.8.3:

Describe the bug We’ve enabled a few warning filters in our application with warning.simplefilter and we’re seeing a python warning when we download a file from the blob storage. ResourceWarning: unclosed <ssl.SSLSocket fd=20, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6, laddr=('10.1.0.62', 52098), raddr=('52.239.140.10', 443)>

To Reproduce

client = BlobServiceClient.from_connection_string("<connection string here>").get_blob_client(container="<container name>", blob="<blob name>")
raw_data = client.download_blob().readall()
with gzip.open(BytesIO(raw_data), "rb") as fh:
    data = pickle.load(fh)  # noqa: S301

Expected behavior No warning or a proper way to close the stream.

Screenshots NA

Additional context NA

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
tasherif-msftcommented, Jan 29, 2021

Hi @lukin0110, this is actually intended behavior. When you run

import warnings
from azure.storage.blob import BlobServiceClient

warnings.simplefilter("default", ResourceWarning)

CONNECTION = "<connection string here>"
CONTAINER = "<container name here>"
BLOB_NAME = "<blob name here>"

client = BlobServiceClient.from_connection_string(CONNECTION).get_blob_client(container=CONTAINER, blob=BLOB_NAME)
raw_data = client.download_blob().readall()

You’re creating a blob client from your BlobServiceClient and not closing any sessions. If you want to ensure all sessions are closed, you must close your parent client. You can achieve this by doing:

BlobServiceClient.from_connection_string(CONNECTION) as bsc:
    bc = bsc.get_blob_client(container="test", blob="blob.txt")
    raw_data = bc.download_blob().readall()

This ensures that the socket is closed since the child class is inheriting the same session.

You can also do:

bsc = BlobServiceClient.from_connection_string(CONNECTION)
bc = bsc.get_blob_client(container="test", blob="blob.txt")
raw_data = bc.download_blob().readall()
bsc.close()

Hope this helps! Let me know if there anything else needed

1reaction
xiafu-msftcommented, Oct 21, 2020

Hi @lukin0110

Thanks for reporting this issue. I was able to reproduce. The problem is we created a session and didn’t close it https://github.com/Azure/azure-sdk-for-python/blame/master/sdk/core/azure-core/azure/core/pipeline/transport/_requests_basic.py#L244

@xiangyan99 could you please find people to confirm we want to close the session before return.

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 ...
Note - one thing that is different that the previous bug is that I'm using an IPv6 control plane, so the addresses in...
Read more >
Incomprehensible warnings in log files - Tryton Discussion
From the port (389) it seems that the connection to the ldap server is not closed properly. Are you using the ldap_authentication module?...
Read more >
Issue 43885: ResourceWarning: unclosed <ssl.SSLSocket ...
SSLSocket fd=5, family=AF_INET, type=SOCK_STREAM, proto=0, laddr=('127.0.0.1', 32937), raddr=('127.0.0.1', 60292)> del self.thread Object ...
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