-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ResourceWarning: unclosed ssl.SSLSocket #454
Comments
I am able to reproduce this. Note you can only reproduce this with python3. More research needs to be done to see if it is an issue with our underlying http library or it is something with our implementation. I have found a few related python bugs, but not sure if those fit the bill especially on Python3.5 I am still seeing them: |
Should probably mention that I'm running python 3.5 as well, 3.5.1 to be specific. |
I'm seeing this as well. Enabling |
I have also run into this since upgrading to python 3.5. From what I can tell it's something to with connection pooling [0]. I have found a way to "fix" the warnings, although I'm not sure it's the correct way to do so: in botocore/awsrequest.py, explicitly set the
[0] https://github.com/kennethreitz/requests/issues/2963#issuecomment-169631513 |
I am also experiencing issues with python 3.5. Had to go back to 2.7. Make sure to use the following command to install AWS cli:
|
Pinging this thread: is there a solution merged somewhere, please? |
+1, also on python 3.5 -- any update? |
+1, seeing on python 3.6 |
+1, seeing on python 3.6.1 |
+1 Still an issue. The fix given by @Naddiseo works. |
+1, seeing on python 3.6.1 |
python 3.6.1 I'm testing cognito. |
+1 boto3=1.4.4, python=3.6.1 |
+1
|
For future readers... I did a little research, and also clicked the link in the above discussion given by @Naddiseo and according to someone working on Requests lib: and So looks like not an issue. Why is it coming up though? It looks like Python is supposed to suppress such warnings by default. Seems like somewhere around 3.2 (?) they changed the behavior of (* edit, added credit where credit is due) |
I find this advice contrary to Python's typical approach to resource handling. Python encourages deterministic resource handling. For example, the stdlib produces warnings when files are mismanaged in a non-deterministic way to help guide developers. Developers should take action on the warnings produced by stdlib. See the following Python bug where core developers discuss warnings during destructors: https://bugs.python.org/issue28867 Additionally, Python docs warn against relying on
And, exceptions occurring during
I run all my tests and environments with warnings enabled to help catch real bugs and upgrade paths. If this warning really should be ignored as suggested here, then maybe it shouldn't be logged. As it is now, people are taking this advice of not calling close and this results in lots of (ignorable?) noise in my output. |
Another work around based upon boto/botocore#1231 is using the event system: def http_closer(http_response, **kwargs):
if http_response:
http_response.close()
s3 = boto3.resource('s3', aws_access_key_id="XXX", aws_secret_access_key="YYY")
events = s3.meta.client.meta.events
# For HeadBucket for example, 'after-call.s3.*' could also work
events.register("after-call.s3.HeadBucket", http_closer)
try:
s3.meta.client.head_bucket(Bucket="mybucket")
except botocore.exceptions.ClientError as e:
print("Could not find bucket", e)
|
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. |
I was receiving the same warning when working with Polly. The following implementation removed the warning. Running python=3.6, Boto3=1.5. # core.py
import boto3
from botocore.exceptions import BotoCoreError
from contextlib import closing
polly = boto3.client('polly')
def polly_stream(text):
try:
response = polly.synthesize_speech(
OutputFormat='mp3',
Text=text,
TextType='text',
VoiceId='Salli',)
with closing(response["AudioStream"]) as stream:
return stream.read()
except BotoCoreError as error:
raise error # test.py
from unittest import main, TestCase
from core import polly_stream
class TestVoice(TestCase):
def test_polly_stream(self):
stream = polly_stream('I')
self.assertIsInstance(stream, bytes)
if __name__ == '__main__':
main()
Hope it helps. |
Same issue for me. If the warning can be safely ignored, please squash it in lib. I don't want to disable all ResourceWarning. Python 3.6.4 on Linux |
Having the same issue. The other fixes did not work for me, but this one did. Added the following to my setUp:
The message parameter is a regex match for the message part of the warning, so this can be adjusted to filter out only this one warning and leave the others intact. Python: 3.6.2 on Windows |
Bumping. |
Hi all, I'm reviewing this with our team. |
@kdaily What's the status after reviewing this with the team? |
I would also like to see some sort of .close() or similar teardown function exposed to eliminate these warnings. Thank you. |
I wouldn't come to that conclusion. It may be difficult to fix without a supporting change in CPython. Edit: I was referring to a now deleted comment. |
I understand your frustration. Your previous comment has been removed as a violation of the Code of Conduct. Please take a moment to review it and keep the conversation productive. Thank you. |
I'll avoid reposting the exact words to avoid the wrath of the censors*, but just to avoid the deletion rendering @hannes-ucsc's reply incoherent to future readers, suffice it to say that the deleted comment tersely suggested that since this bug has not been fixed in 5 years it is clear that the maintainers do not consider it worth their time and will not fix it. * (well, hopefully, at least. @kdaily gives no indication of what precisely was deemed a CoC violation so we have to guess. Perhaps it was the meaning and not the phrasing that was deemed objectionable and I'm about to get CoCed too. 🤷) |
Hi @ExplodingCabbage - I'm Tom and I manage the Developer Support team for the AWS SDKs (that is, the team that is responsible for managing our GitHub issues for the SDKs). It's well-taken feedback that sometimes moderation decisions can lead to other readers wondering what happened. This isn't uncommon in Internet communities, but I've asked the team to try and be more descriptive when possible if we do have to take moderation action on a comment. There may be reasons why we're unable to share why we reached a decision on a moderation action but that should be the exception rather than the rule. @kdaily already linked our Code of Conduct, but to answer your specific question we decided to take action because we felt this comment did not "use welcoming and inclusive language" and could "reasonably be considered inappropriate in a professional setting". The best way to let us know an issue is important to you is by reacting to it with a 👍, ❤️, 🚀, or 👀. We have internal tooling that sorts feature request issues by these comment reactions and use that data to plan future work. We also use other reactions, number of comments, and other data to drive those decisions, but the reactions are one of the most important. About this issue: I know the team is planning on addressing it soon. We should have replied earlier with a status update, but your feedback does mean that this is important to us. It has fallen down in the priority list because it appears that this is a nuisance warning, but the community feedback means we're still watching. |
@kellertk Yeah, I figured the language used was probably the reason. Without it being explicitly stated, one can never be sure, though! |
Hi everyone, We completely understand the annoyance with having the warning in your logs. To be clear, there are no performance implications by this warning, it's a loud misnomer. Many of you likely don't care about the cause and are looking for a way to reduce the noise though. Most of the relevant information is now buried in this thread, so I'll provide a brief overview of the issue and then we can talk solutions. OverviewWe're hesitant to handle this warning in botocore itself. We don't have a clear indicator when the warning is actually valid and would risk unintentionally masking real problems. As @hannes-ucsc recently noted, they provided a very useful explanation of the underlying issue in CPython. urllib3 keeps connections alive in a pool for performance reasons, however, CPython doesn't recognize this and warns that they haven't been appropriately cleaned up. Removing these warnings entirely would require a change at that level. SolutionsThere have been a few notable proposals in boto/botocore#1231 and boto/botocore#1810. Both have some concerns that aren't easy to address which I'll highlight below. boto/botocore#1231 presents a solution of trying to close on every call. The problem here is urllib3 is returning a ConnectionPool, not a Connection, despite the confusing naming. That means we're now tearing down our entire pool on each call which is going to have a non-trivial performance hit for the average user. This makes a change like this a non-starter. boto/botocore#1810 has some surprising side effects that are going to catch people. When the user calls Of the two proposals, boto/botocore#1810 is the more acceptable given the amount of demand. We do need to make sure the implications are clearly documented for users though. We'll start looking at driving a conclusion on boto/botocore#1810 that will enable managing this manually. |
bumping! |
Hi @lukasschmit, thanks for checking in, we're still aware of the request. Generally, posting bumps isn't helpful in GitHub issues because it buries relevant responses. We're actively tracking the work but it's blocked behind other recent changes. We'll post an update here when it's ready to be merged. |
Alright, I've fixed the remaining blockers and the Users can force connection cleanup by either calling client = boto3.client(service_name='s3')
buckets = client.list_buckets()
client.close() or Wrap your client with the closing context manager: from contextmanager import closing
with closing(boto3.client(service_name='s3')) as client:
buckets = client.list_buckets() Again we'll reiterate that the warnings themselves are not an issue. It's an issue in the standard library incorrectly warning because urllib3 keeps connections alive in our ConnectionPool. They are managed and will be reclaimed when appropriate. For users who want to avoid the warnings, but not suppress them with a filter, Note that calling |
|
For the record, @nateprewitt means boto/botocore#1810 (in botocore) not the link in boto3 |
Great note @wimglenn, I'll update the original. Thanks! |
For python 3.10:
|
Issue: ResourceWarning: unclosed ssl.SSLSocket is it possible to use the s3 client as/within a context manager? this way we can resolve the close() issue for respective usage specifically but not close down on all other parallel sessions or decrease in performance |
For some reason I'm getting a ResourceWarning about a unclosed socket, even when I'm specifically closing the socket myself. See testcase below:
Fill in any
BUCKET
andKEY
to see the problem. Attaching my output below:The text was updated successfully, but these errors were encountered: