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

Connections aren't being closed #140

Closed
dougli opened this issue Nov 24, 2022 · 4 comments · Fixed by #478
Closed

Connections aren't being closed #140

dougli opened this issue Nov 24, 2022 · 4 comments · Fixed by #478

Comments

@dougli
Copy link

dougli commented Nov 24, 2022

The library uses requests to fetch data from OpenAI servers, but we never call .close() on those connections which leaves dangling open file handles on the OS.

Can we clean these connections up gracefully, either after a period of time, or after making a request? There is an advantage to leaving it open as it doesn't have to do the HTTPS handshake on every request, but we should clean this up properly after a period of idleness.

This bug interacts very poorly with another bug in Docker Desktop -- moby/vpnkit#587; the openai library stops working entirely after running it in a Docker container on Mac / Windows for a few minutes. All requests to OpenAI servers time out indefinitely.

@hallacy
Copy link
Collaborator

hallacy commented Dec 2, 2022

Hi @dougli!

Thanks for writing in. I'll surface this to the team and get it on our roadmap. That said, we happily accept PRs if you'd like to take a shot at fixing this.

@sphaero
Copy link

sphaero commented Mar 22, 2023

Any pointers where the sockets are opened or where they should be closed? I'm running into this issue

@sphaero
Copy link

sphaero commented Mar 22, 2023

In my case it helps to ignore the ResourceWarning by adding:

import warnings

warnings.simplefilter("ignore", ResourceWarning)

Doesn't fix the open filedescriptors, though

@bauefikapa
Copy link

We have deployed a dockerized application in production which crashes periodically because of this. Over time more and more connections are being opened until the container crashes because of a memory error.

jhallard added a commit that referenced this issue Jun 5, 2023
…ndle issues (#179)

As reported from the field - we create a `requests.Session` object on first request to the servers and then reuse it indefinitely. This can leave some open
file handles on the OS (not a big deal), but can interact poorly with a bug in Docker Desktop which causes the SDK to entierly break connections to the server.
See #140 for more info.
jhallard added a commit that referenced this issue Jun 6, 2023
… with Docker Desktop (#478)

* Periodically refresh open `requests.Session`s to mitigate open filehandle issues (#179)

As reported, we create a `requests.Session` object on first request to the servers and then reuse it indefinitely. This can leave some open file handles on the OS (not a big deal), but can interact poorly with a bug in Docker Desktop which causes the SDK to entierly break connections to the server.
See #140 for more info.

The order of items in the API responses is intentional, and this order is clobbered by the rendering of `OpenAIObject`. This change removes the alphabetic sort of response keys
happydeveloper0305 added a commit to happydeveloper0305/openai_python that referenced this issue May 9, 2024
… with Docker Desktop (#478)

* Periodically refresh open `requests.Session`s to mitigate open filehandle issues (#179)

As reported, we create a `requests.Session` object on first request to the servers and then reuse it indefinitely. This can leave some open file handles on the OS (not a big deal), but can interact poorly with a bug in Docker Desktop which causes the SDK to entierly break connections to the server.
See openai/openai-python#140 for more info.

The order of items in the API responses is intentional, and this order is clobbered by the rendering of `OpenAIObject`. This change removes the alphabetic sort of response keys
byteman0125 pushed a commit to byteman0125/openai-python that referenced this issue Jun 14, 2024
… with Docker Desktop (#478)

* Periodically refresh open `requests.Session`s to mitigate open filehandle issues (#179)

As reported, we create a `requests.Session` object on first request to the servers and then reuse it indefinitely. This can leave some open file handles on the OS (not a big deal), but can interact poorly with a bug in Docker Desktop which causes the SDK to entierly break connections to the server.
See openai/openai-python#140 for more info.

The order of items in the API responses is intentional, and this order is clobbered by the rendering of `OpenAIObject`. This change removes the alphabetic sort of response keys
risingstar0225 added a commit to risingstar0225/openai_py that referenced this issue Jul 26, 2024
… with Docker Desktop (#478)

* Periodically refresh open `requests.Session`s to mitigate open filehandle issues (#179)

As reported, we create a `requests.Session` object on first request to the servers and then reuse it indefinitely. This can leave some open file handles on the OS (not a big deal), but can interact poorly with a bug in Docker Desktop which causes the SDK to entierly break connections to the server.
See openai/openai-python#140 for more info.

The order of items in the API responses is intentional, and this order is clobbered by the rendering of `OpenAIObject`. This change removes the alphabetic sort of response keys
megamanics pushed a commit to devops-testbed/openai-python that referenced this issue Aug 14, 2024
… with Docker Desktop (openai#478)

* Periodically refresh open `requests.Session`s to mitigate open filehandle issues (openai#179)

As reported, we create a `requests.Session` object on first request to the servers and then reuse it indefinitely. This can leave some open file handles on the OS (not a big deal), but can interact poorly with a bug in Docker Desktop which causes the SDK to entierly break connections to the server.
See openai#140 for more info.

The order of items in the API responses is intentional, and this order is clobbered by the rendering of `OpenAIObject`. This change removes the alphabetic sort of response keys
Watcher919 added a commit to Watcher919/Python-openAI that referenced this issue Sep 4, 2024
… with Docker Desktop (#478)

* Periodically refresh open `requests.Session`s to mitigate open filehandle issues (#179)

As reported, we create a `requests.Session` object on first request to the servers and then reuse it indefinitely. This can leave some open file handles on the OS (not a big deal), but can interact poorly with a bug in Docker Desktop which causes the SDK to entierly break connections to the server.
See openai/openai-python#140 for more info.

The order of items in the API responses is intentional, and this order is clobbered by the rendering of `OpenAIObject`. This change removes the alphabetic sort of response keys
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants