Skip to content

Open AI Clients starts timing out after some time in production #2688

@AshuBik

Description

@AshuBik

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

A weird issue that I am facing in production, after the code is deployed and it has been 24-26 hours the any calls made using the above client start timing out. Usually taking out a redeployment helps.

This pattern makes it feel like the underlying HTTP connections are not being released or refreshed correctly, which may be causing a connection pool exhaustion.

Any best practices or recommendations on how to tackle this ?

My configuration

openai.api_key = os.environ.get("OPENAI_API_KEY") os.environ.setdefault("OPENAI_LOG", "debug") client = AsyncOpenAI( http_client=DefaultAioHttpClient( limits=httpx.Limits(max_connections=1000, max_keepalive_connections=100) ), ) 

I am streaming and once i am done with streaming I am closing the stream as well

response = return await chat_client.chat.completions.create(**params) ## Later on if response: await response.close() 
name = "openai" version = "1.99.9" 

To Reproduce

  • NA since it it not easily replicable in local.

Code snippets

OS

Debian Linux

Python version

3.10.6

Library version

1.99.9

Metadata

Metadata

Assignees

No one assigned

    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