Skip to content

OSError: [Errno 24] Too many open files during retry  #933

Closed
@elisa-abridge

Description

@elisa-abridge

Confirm this is an issue with the Python library and not an underlying OpenAI API

  • This is an issue with the Python library

Describe the bug

Our retry logic was successful before migration to openai v1.0.0. However, now the retry fails as described below.

After a call to openai's API chat.completions.create fails with a Connection Error, our code will catch the exception and retry. However, the retry fails with the following error:

  File "<our code>.py", line xxx, in <our_method1>
  File "/opt/conda/envs/pbap_prompt/lib/python3.10/site-packages/nest_asyncio.py", line 35, in run
  File "/opt/conda/envs/pbap_prompt/lib/python3.10/site-packages/nest_asyncio.py", line 90, in run_until_complete
  File "/opt/conda/envs/pbap_prompt/lib/python3.10/asyncio/futures.py", line 201, in result
  File "/opt/conda/envs/pbap_prompt/lib/python3.10/asyncio/tasks.py", line 232, in __step
  File "<our code>.py", line xxx, in <our_method2>
  File "/opt/conda/envs/pbap_prompt/lib/python3.10/site-packages/openai/_client.py", line 317, in __init__
  File "/opt/conda/envs/pbap_prompt/lib/python3.10/site-packages/openai/_base_client.py", line 1190, in __init__
  File "/opt/conda/envs/pbap_prompt/lib/python3.10/site-packages/httpx/_client.py", line 1397, in __init__
  File "/opt/conda/envs/pbap_prompt/lib/python3.10/site-packages/httpx/_client.py", line 1445, in _init_transport
  File "/opt/conda/envs/pbap_prompt/lib/python3.10/site-packages/httpx/_transports/default.py", line 272, in __init__
  File "/opt/conda/envs/pbap_prompt/lib/python3.10/site-packages/httpx/_config.py", line 51, in create_ssl_context
  File "/opt/conda/envs/pbap_prompt/lib/python3.10/site-packages/httpx/_config.py", line 75, in __init__
  File "/opt/conda/envs/pbap_prompt/lib/python3.10/site-packages/httpx/_config.py", line 87, in load_ssl_context
  File "/opt/conda/envs/pbap_prompt/lib/python3.10/site-packages/httpx/_config.py", line 145, in load_ssl_context_verify
OSError: [Errno 24] Too many open files

Here is a snippet of our methods:

method1:

        try:
            outputs = asyncio.run(
                                method2
             )

method2:

          AsyncOpenAI(
            api_key=xxx,
            organization=xxx,
            max_retries=0,
        ).chat.completions.create(
                    model=model,
                    messages=input_data,
                    max_tokens=max_new_tokens,
                    temperature=temperature,
                    timeout=timeout,
                )
            )

To Reproduce

  1. create openai async client and call chat.completions.create
  2. openai returns error such as Connection Error
  3. catch error and create new openai async client and call chat.completions.create again
  4. receive error OSError: [Errno 24] Too many open files

Code snippets

See above

OS

Unix Ubuntu

Python version

Python v3.10.0

Library version

openai 1.3.5

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions