improve OkHttpClient reuse & efficiency#1131
Merged
Merged
Conversation
- Reuses `OkHttpClient` for identical auth tokens, reducing memory usage. - Ensures thread-safe access with a lock. - Creates new instances only when the auth token changes. - Extracts timeouts as constants.
a0a5128 to
f1ecc2b
Compare
|
luhmirin-s
approved these changes
Mar 10, 2025
Contributor
luhmirin-s
left a comment
There was a problem hiding this comment.
This change feels unsafe, but I cannot pin-point why :D
BurningAXE
reviewed
Mar 12, 2025
|
|
||
| fun get( | ||
| private var okHttpClient: OkHttpClient? = null | ||
| private var currentAuthToken: String? = null |
Contributor
There was a problem hiding this comment.
Just to double check - once logged in, we always use just one auth token for all calls going through OkHttp!?
Collaborator
Author
There was a problem hiding this comment.
Yes, We use the same firebase auth token in every authenticated api request
if the token changed then the BuildOkHttpClientUseCase will create another OK http client
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.



JIRA ticket
Will be released in: 2025.2.0
Root cause analysis (for bugfixes only)
First known affected version:From the moment we started using OkHttp
The issue was identified through this Crashlytics OOM error, revealing that OkHttp had created 300 threads. After reviewing the OkHttp documentation, I discovered that SID was incorrectly creating a new
OkHttpClientinstance for each API call instead of reusing a single instance.Notable changes
OkHttpClientfor identical auth tokens, reducing memory usage.Testing guidance
As the change is in the network layer then all general api calls should be checked
Additional work checklist