fix(client): reuse httpx client in get_client#1482
Merged
Conversation
Contributor
Greptile's behavior is changing!From now on, if a review finishes with no comments, we will not post an additional "statistics" comment to confirm that our review found nothing to comment on. However, you can confirm that we reviewed your changes in the status check section. This feature can be toggled off in your Code Review Settings by deselecting "Create a status check for each PR". |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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