Skip to content
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 socket #2153

Closed
2 tasks done
kbaikov opened this issue Mar 8, 2020 · 6 comments · Fixed by #4643
Closed
2 tasks done

ResourceWarning: unclosed socket #2153

kbaikov opened this issue Mar 8, 2020 · 6 comments · Fixed by #4643
Labels
kind/bug Something isn't working as expected

Comments

@kbaikov
Copy link

kbaikov commented Mar 8, 2020

  • I have searched the issues of this repo and believe that this is not a duplicate.
  • I have searched the documentation and believe that my question is not covered.

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:

@kasteph kasteph added the kind/bug Something isn't working as expected label Mar 8, 2020
@kbaikov
Copy link
Author

kbaikov commented Jan 16, 2021

Ping @stephsamson
Any activity on this bug?

@ShahriyarR
Copy link

ShahriyarR commented May 15, 2021

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 added a commit to kkirsche/poetry that referenced this issue Oct 15, 2021
Relates to: python-poetry#2153
When running `poetry update`, during the download phase when `PYTHONWARNINGS="default"` environment variable is set, multiple different sessions trigger resource warnings. This fixes one of them that occurs during the download phase of the package update.

```
/Users/username/Library/Application Support/pypoetry/venv/lib/python3.10/site-packages/poetry/installation/executor.py:594: ResourceWarning: unclosed <ssl.SSLSocket fd=5, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=0, laddr=('REDACTED', 59025), raddr=('140.108.3.33', 80)>
```

This line references:
```
 593   │             try:
 594   │                 archive = self._download_archive(operation, link)
 595   │             except BaseException:
 596   │                 cache_directory = self._chef.get_cache_directory_for_link(link)
```

The issue is being caused because the session is being left open when the class is later cleaned up. By adding a destructor method, we can close the session if it exists, preventing this error.
kkirsche added a commit to kkirsche/poetry that referenced this issue Oct 15, 2021
Relates to: python-poetry#2153
When running `poetry update`, during the download phase when `PYTHONWARNINGS="default"` environment variable is set, multiple different sessions trigger resource warnings. This fixes one of them that occurs during the download phase of the package update.

```
/Users/username/Library/Application Support/pypoetry/venv/lib/python3.10/site-packages/poetry/installation/executor.py:594: ResourceWarning: unclosed <ssl.SSLSocket fd=5, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=0, laddr=('REDACTED', 59025), raddr=('140.108.3.33', 80)>
```

This line references:
```
 593   │             try:
 594   │                 archive = self._download_archive(operation, link)
 595   │             except BaseException:
 596   │                 cache_directory = self._chef.get_cache_directory_for_link(link)
```

The issue is being caused because the session is being left open when the class is later cleaned up. By adding a destructor method, we can close the session if it exists, preventing this error.
kkirsche added a commit to kkirsche/poetry that referenced this issue Oct 15, 2021
Relates to: python-poetry#2153
When running `poetry update`, during the download phase when `PYTHONWARNINGS="default"` environment variable is set, multiple different sessions trigger resource warnings. This fixes one of them that occurs during the download phase of the package update.

```
/Users/username/Library/Application Support/pypoetry/venv/lib/python3.10/site-packages/poetry/installation/executor.py:594: ResourceWarning: unclosed <ssl.SSLSocket fd=5, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=0, laddr=('REDACTED', 59025), raddr=('140.108.3.33', 80)>
```

This line references:
```
 593   │             try:
 594   │                 archive = self._download_archive(operation, link)
 595   │             except BaseException:
 596   │                 cache_directory = self._chef.get_cache_directory_for_link(link)
```

The issue is being caused because the session is being left open when the class is later cleaned up. By adding a destructor method, we can close the session if it exists, preventing this error.
@kkirsche
Copy link
Contributor

kkirsche commented Oct 15, 2021

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
Copy link
Author

kbaikov commented Oct 15, 2021 via email

@kbaikov
Copy link
Author

kbaikov commented Oct 15, 2021

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

neersighted pushed a commit to kkirsche/poetry that referenced this issue Nov 15, 2021
Relates to: python-poetry#2153
When running `poetry update`, during the download phase when `PYTHONWARNINGS="default"` environment variable is set, multiple different sessions trigger resource warnings. This fixes one of them that occurs during the download phase of the package update.

```
/Users/username/Library/Application Support/pypoetry/venv/lib/python3.10/site-packages/poetry/installation/executor.py:594: ResourceWarning: unclosed <ssl.SSLSocket fd=5, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=0, laddr=('REDACTED', 59025), raddr=('140.108.3.33', 80)>
```

This line references:
```
 593   │             try:
 594   │                 archive = self._download_archive(operation, link)
 595   │             except BaseException:
 596   │                 cache_directory = self._chef.get_cache_directory_for_link(link)
```

The issue is being caused because the session is being left open when the class is later cleaned up. By adding a destructor method, we can close the session if it exists, preventing this error.
neersighted pushed a commit that referenced this issue Nov 15, 2021
Relates to: #2153
When running `poetry update`, during the download phase when `PYTHONWARNINGS="default"` environment variable is set, multiple different sessions trigger resource warnings. This fixes one of them that occurs during the download phase of the package update.

```
/Users/username/Library/Application Support/pypoetry/venv/lib/python3.10/site-packages/poetry/installation/executor.py:594: ResourceWarning: unclosed <ssl.SSLSocket fd=5, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=0, laddr=('REDACTED', 59025), raddr=('140.108.3.33', 80)>
```

This line references:
```
 593   │             try:
 594   │                 archive = self._download_archive(operation, link)
 595   │             except BaseException:
 596   │                 cache_directory = self._chef.get_cache_directory_for_link(link)
```

The issue is being caused because the session is being left open when the class is later cleaned up. By adding a destructor method, we can close the session if it exists, preventing this error.
1nF0rmed pushed a commit to 1nF0rmed/poetry that referenced this issue Nov 15, 2021
Relates to: python-poetry#2153
When running `poetry update`, during the download phase when `PYTHONWARNINGS="default"` environment variable is set, multiple different sessions trigger resource warnings. This fixes one of them that occurs during the download phase of the package update.

```
/Users/username/Library/Application Support/pypoetry/venv/lib/python3.10/site-packages/poetry/installation/executor.py:594: ResourceWarning: unclosed <ssl.SSLSocket fd=5, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=0, laddr=('REDACTED', 59025), raddr=('140.108.3.33', 80)>
```

This line references:
```
 593   │             try:
 594   │                 archive = self._download_archive(operation, link)
 595   │             except BaseException:
 596   │                 cache_directory = self._chef.get_cache_directory_for_link(link)
```

The issue is being caused because the session is being left open when the class is later cleaned up. By adding a destructor method, we can close the session if it exists, preventing this error.
edvardm pushed a commit to edvardm/poetry that referenced this issue Nov 24, 2021
Relates to: python-poetry#2153
When running `poetry update`, during the download phase when `PYTHONWARNINGS="default"` environment variable is set, multiple different sessions trigger resource warnings. This fixes one of them that occurs during the download phase of the package update.

```
/Users/username/Library/Application Support/pypoetry/venv/lib/python3.10/site-packages/poetry/installation/executor.py:594: ResourceWarning: unclosed <ssl.SSLSocket fd=5, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=0, laddr=('REDACTED', 59025), raddr=('140.108.3.33', 80)>
```

This line references:
```
 593   │             try:
 594   │                 archive = self._download_archive(operation, link)
 595   │             except BaseException:
 596   │                 cache_directory = self._chef.get_cache_directory_for_link(link)
```

The issue is being caused because the session is being left open when the class is later cleaned up. By adding a destructor method, we can close the session if it exists, preventing this error.
Copy link

github-actions bot commented Mar 2, 2024

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/bug Something isn't working as expected
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants