fix(client): reuse httpx client in get_client #1482
Merged
+1
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Important
Reuse existing
httpx_clientin_create_client_from_instance()inget_client.pyto improve performance.httpx_clientin_create_client_from_instance()inget_client.pyto improve performance by avoiding new client creation.httpx_client=instance.httpx_clientparameter to_create_client_from_instance()inget_client.py.This description was created by
for ce6c6c5. You can customize this summary. It will automatically update as commits are pushed.
Disclaimer: Experimental PR review
Greptile Summary
This PR fixes a bug in
_create_client_from_instancewhere thehttpx_clientwas not being passed when creating a newLangfuseclient from an existingLangfuseResourceManagerinstance. This ensures proper reuse of the httpx connection pool, preventing potential TCP socket exhaustion issues as documented in the codebase.httpx_client=instance.httpx_clientparameter to theLangfuseconstructor call in_create_client_from_instanceConfidence Score: 5/5
Important Files Changed
httpx_clientparameter to_create_client_from_instanceto reuse the existing httpx client from the resource manager instance, preventing potential connection pool exhaustion.Sequence Diagram
sequenceDiagram participant User participant get_client participant _create_client_from_instance participant Langfuse participant LangfuseResourceManager User->>get_client: get_client() get_client->>LangfuseResourceManager: Check _instances alt Instance exists get_client->>_create_client_from_instance: Create client from instance _create_client_from_instance->>Langfuse: new Langfuse(httpx_client=instance.httpx_client) Langfuse->>LangfuseResourceManager: Get singleton (reuses existing) Note right of LangfuseResourceManager: Reuses existing httpx_client<br/>from connection pool Langfuse-->>_create_client_from_instance: Return client _create_client_from_instance-->>get_client: Return client end get_client-->>User: Return Langfuse client