Skip to content
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

Fix memory leak when using ktor-client-java #4637

Merged
merged 1 commit into from
Nov 16, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public BodySubscriber<T> apply(ResponseInfo responseInfo) {
if (subscriber instanceof BodySubscriberWrapper) {
return subscriber;
}
return new BodySubscriberWrapper<>(delegate.apply(responseInfo), context);
return new BodySubscriberWrapper<>(subscriber, context);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please explain, why the previous version caused the memory leak?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the line before the diff there is BodySubscriber<T> subscriber = delegate.apply(responseInfo); Apparently in case of ktor the result of delegate.apply which is a JavaHttpResponseBodySubscriber https:/ktorio/ktor/blob/main/ktor-client/ktor-client-java/jvm/src/io/ktor/client/engine/java/JavaHttpResponseBodyHandler.kt can't just be thrown away without closing it. Anyway I believe that I'm the author of this bug, it should have looked like this from the start.

}

public static class BodySubscriberWrapper<T> implements BodySubscriber<T> {
Expand Down