Ensure timeout is applied at HttpUrlConenction level#403
Merged
Conversation
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.
Changes in this pull request
Checklist
CHANGELOG.mdfor any breaking changes, enhancements, or bug fixes.ktlintin the main directory and fixed any issues.Greptile Summary
This PR propagates a
timeout: Duration?parameter throughNetworkService,NetworkRequestData, andRequestExecutorto setHttpURLConnection.connectTimeoutandreadTimeout, ensuring blocking HTTP calls are bounded. Specific timeouts are wired up inEnrichmentService(already had a coroutine-level guard) andSubscriptionService(no coroutine guard).connectTimeoutandreadTimeoutare independent phases; setting both toTmeans the maximum HTTP-level block is2×T. ForSubscriptionServicecalls (no coroutine-levelwithTimeout), a 5 s configured timeout can actually block for up to 10 s.toInt()oninWholeMillisecondssilently overflows for durations > ~24.8 days; acoerceInguard is a cheap safety net.Confidence Score: 3/5
The PR improves the status quo but the doubled effective timeout at the HTTP layer means configured timeout values are not enforced as intended for SubscriptionService calls.
A P1 finding (effective timeout is silently 2× the configured value for callers without a coroutine guard) pulls the score below the P1 ceiling of 4. The fix is contained to RequestExecutor and is straightforward, so it does not drop further.
superwall/src/main/java/com/superwall/sdk/network/RequestExecutor.kt — the connectTimeout/readTimeout assignment is where the doubled-timeout defect lives.
Important Files Changed
connectTimeoutandreadTimeoutfromNetworkRequestData.timeout; both are set to the same value, doubling the effective maximum HTTP-level wait, andtoInt()can silently overflow for very large durations.timeout: Duration?field; propagated correctly throughcopyWithUrl, but missing a default value on the constructor which is a minor source-compatibility concern.timeout: Duration? = nullthroughget()andpost()helpers intoNetworkRequestData; looks correct.redeemToken, 5 s for entitlement GETs) with no coroutine-level guard, so the effective maximum blocking time is 2× the configured value due to the separateconnectTimeout/readTimeoutissue inRequestExecutor.timeouttopost()alongside the existingeitherWithTimeoutcoroutine guard; the coroutine guard remains the primary enforcer, with the HTTP timeouts as a safety net.Sequence Diagram
sequenceDiagram participant S as Service (Enrichment/Subscription) participant NS as NetworkService participant CE as CustomHttpUrlConnection participant RE as RequestExecutor participant HUC as HttpURLConnection S->>NS: get/post(path, timeout=T) NS->>CE: request(buildRequestData, retryCount) CE->>RE: execute(NetworkRequestData(timeout=T)) RE->>HUC: openConnection() RE->>HUC: connectTimeout = T.inWholeMilliseconds.toInt() RE->>HUC: readTimeout = T.inWholeMilliseconds.toInt() Note over HUC: Max HTTP wait = connectTimeout + readTimeout = 2×T HUC-->>RE: responseCode / data RE-->>CE: Either<RequestResult, NetworkError> CE-->>NS: Either<T, NetworkError> NS-->>S: Either<T, NetworkError>Prompt To Fix All With AI
Reviews (1): Last reviewed commit: "Ensure timeout is applied at HttpUrlCone..." | Re-trigger Greptile