Integrated: 8294916: Cancelling a request must eventually cause its response body subscriber to be unregistered

Daniel Fuchs dfuchs at openjdk.org
Thu Oct 20 08:52:38 UTC 2022


On Tue, 11 Oct 2022 15:49:14 GMT, Daniel Fuchs <dfuchs at openjdk.org> wrote:

> When [JDK-8277969](https://bugs.openjdk.org/browse/JDK-8277969) was implemented, a list of outstanding response subscribers was added to `HttpClientImpl`. A body subscriber is added to the list after being created and is removed from the list when it is completed, either successfully or exceptionally.
> 
> It appears that in the case where the subscription is cancelled before the subscriber is completed, the subscriber might remain registered in the list forever, or at least until the HttpClient gets garbage collected. This can be easily reproduced using streaming subscribers, such as BodySubscriber::ofInputStream. In the case where the input stream is closed without having read all the bytes, Subscription::cancel will be called. Whether the subscriber gets unregistered or not at that point becomes racy.
> 
> Indeed, the reactive stream specification doesn't guarantee whether onComplete or onError will be called or not after a subscriber cancels its subscription. Any cleanup that would have been performed by onComplete/onError might therefore need to be performed when the subscription is cancelled too.

This pull request has now been integrated.

Changeset: dcd46501
Author:    Daniel Fuchs <dfuchs at openjdk.org>
URL:       https://git.openjdk.org/jdk/commit/dcd46501e6a25ac875d61bfbd412555b933ce34c
Stats:     645 lines in 9 files changed: 620 ins; 1 del; 24 mod

8294916: Cancelling a request must eventually cause its response body subscriber to be unregistered

Reviewed-by: michaelm, jpai

-------------

PR: https://git.openjdk.org/jdk/pull/10659


More information about the net-dev mailing list