New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't leak response bodies in executeAsync #8330
Conversation
b1f97d5
to
7570f26
Compare
Also make callers opt in to an unstable coroutines API. If the resource cleanup coroutines API changes, we'll have to change this API. Remove the OkHttp experimental API. This is a good enough API as far as OkHttp is concerned.
@@ -42,7 +42,9 @@ suspend fun Call.executeAsync(): Response = | |||
call: Call, | |||
response: Response, | |||
) { | |||
continuation.resume(value = response, onCancellation = { call.cancel() }) | |||
continuation.resume(response) { | |||
response.closeQuietly() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am naughty and did both a formatting change and a behavior change here.
Used to be cancel -- asynchronously interrupt a call without releasing any resources
Now it’s close -- synchronously release resources
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should Retrofit borrow this improvement in retrofit2/KotlinExtensions.kt
? @JakeWharton
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Retrofit doesn't have this problem. We never pass a live resource across the coroutine boundary. Our underlying request has already been completely consumed and closed before we resume.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Retrofit doesn't have this problem. We never pass a live resource across the coroutine boundary. Our underlying request has already been completely consumed and closed before we resume.
Got it, thanks
import okio.IOException | ||
|
||
@OptIn(ExperimentalCoroutinesApi::class) | ||
@ExperimentalOkHttpApi | ||
@ExperimentalCoroutinesApi // resume with a resource cleanup. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
7570f26
to
f484cc5
Compare
Also make callers opt in to an unstable coroutines API. If the resource
cleanup coroutines API changes, we'll have to change this API.
Remove the OkHttp experimental API. This is a good enough API as far
as OkHttp is concerned.