> The HttpBodySubscriberWrapper is a class that ensures that a subscriber will 
> be subscribed to before it is completed. It also provides hooks to its two 
> subclasses (one for HTTP/1, one for HTTP/2) that allows subclasses to 
> register the susbscriber with the HttpClient at subscription time, and to 
> unregister it when it is eventualy completed, or when the subscription is 
> cancelled.
> 
> There is however a race condition that can happen when a subscription is 
> cancelled: it can happen that unregister is called before register. The 
> CancelRequestTest has been observed failing once or twice on personal jobs. 
> Though the particular mechanics of this race is hard to understand, the logs 
> of the tests have brought sufficient evidence that this is what was 
> happening. 
> 
> The symptom is finding one subscriber still registered after completion of 
> the exchange:
> 
> test 
> CancelRequestTest.testGetSendAsync("https://localhost:42711/https1/x/same/interrupt";,
>  true, true): failure
> java.lang.AssertionError: WARNING: tracker for HttpClientImpl(13) has 
> outstanding operations:
> Pending HTTP Requests: 0
> Pending HTTP/1.1 operations: 0
> Pending HTTP/2 streams: 0
> Pending WebSocket operations: 0
> Pending TCP connections: 0
> Pending Subscribers: 1
> Total pending operations: 0
> Facade referenced: true
> Selector alive: true
> 
> The proposed fix hoist special hooks for register/unregister in the 
> superclass, merges all various volatile boolean states into a single int 
> state, and protect the state changes  to subscribed/register/unregister by 
> the same subscription lock.
> If cancelling the subscription happens at around the same time that the 
> subscriber is subscribed this ensures that the subscriber won't be removed 
> from the map before it is added.

Daniel Fuchs has updated the pull request with a new target base due to a merge 
or a rebase. The incremental webrev excludes the unrelated changes brought in 
by the merge/rebase. The pull request contains six additional commits since the 
last revision:

 - Copyright year updates
 - Merge branch 'HttpBodySubscriberWrapper-8302635' of 
https://github.com/dfuch/jdk into HttpBodySubscriberWrapper-8302635
 - Update 
src/java.net.http/share/classes/jdk/internal/net/http/common/HttpBodySubscriberWrapper.java
   
   make `state` private
 - Merge branch 'master' into HttpBodySubscriberWrapper-8302635
 - Fixed boolean cancelled() {}
 - 8302635

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

Changes:
  - all: https://git.openjdk.org/jdk/pull/12587/files
  - new: https://git.openjdk.org/jdk/pull/12587/files/47887520..1f3e2ba7

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk&pr=12587&range=03
 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=12587&range=02-03

  Stats: 2934 lines in 99 files changed: 1953 ins; 705 del; 276 mod
  Patch: https://git.openjdk.org/jdk/pull/12587.diff
  Fetch: git fetch https://git.openjdk.org/jdk pull/12587/head:pull/12587

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

Reply via email to