python-poetry / poetry

Python packaging and dependency management made easy
https://python-poetry.org
MIT License
31.02k stars 2.25k forks source link

ResourceWarning: unclosed socket #2153

Closed kbaikov closed 2 years ago

kbaikov commented 4 years ago

Issue

If i run python with warnings enabled (set the env var PYTHONWARNINGS="default" ), and try to do poetry update or any remote connection related operation i get the following message:

C:\Users\<username>\.poetry\lib\poetry\console\application.py:54: ResourceWarning: unclosed <ssl.SSLSocket fd=868, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=0, laddr=('157.163.199.78', 57798), raddr=('151.101.192.223', 443)>
  self._poetry = None
ResourceWarning: Enable tracemalloc to get the object allocation traceback

Poetry version 1.0.5 Python 3.8.2 x64 Windows 10

Update: added the fuller message with the location of the warning in code: C:\Users\<username>\.poetry\lib\poetry\console\application.py:54:

kbaikov commented 3 years ago

Ping @stephsamson Any activity on this bug?

ShahriyarR commented 3 years ago

The same warning I got while doing:

$ poetry install
Updating dependencies
Resolving dependencies... (0.4s)/home/shako/.poetry/lib/poetry/repositories/pypi_repository.py:207: ResourceWarning: unclosed <ssl.SSLSocket fd=3, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6, laddr=('192.168.1.57', 50624), raddr=('151.101.64.223', 443)>
  data = self._get("pypi/{}/json".format(name))
ResourceWarning: Enable tracemalloc to get the object allocation traceback

Python 3.9 and Ubuntu 18.04

kkirsche commented 2 years ago

PR submitted. If this is bugging you the patch locally is pretty simple also. ~8 or so lines. The root of the issue is that a session with keep alive behavior is used but the session is not being explicitly closed at the time the class gets cleaned up by the garbage collector after it's done being used.

kbaikov commented 2 years ago

Perfect, thank you. I will apply and test it locally in the evening.

On Fri, 15 Oct 2021, 13:11 Kevin Kirsche @.***> wrote:

PR submitted. If this is bugging you the patch locally is pretty simple also. ~8 or so lines.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/python-poetry/poetry/issues/2153#issuecomment-944214288, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABCH53ZFTPDHDWMYHUYZPPLUHAD55ANCNFSM4LD4DOFQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

kbaikov commented 2 years ago

The fix works for me with Poetry (version 1.2.0a2) and Python 3.10

github-actions[bot] commented 6 months ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.