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

8297149: REDO JDK-8296889: Race condition when cancelling a request #11193

Closed
wants to merge 3 commits into from

Conversation

dfuch
Copy link
Member

@dfuch dfuch commented Nov 16, 2022

Please find here a re-do fix for the race condition while cancelling request.
The previous fix failed because it registered the subscriber too late (after having called userSubsciber.onSubscribe()), which opened a window for the call to unregister to occur before the call to register.
This is fixed in this new iteration.


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issues

  • JDK-8297149: REDO JDK-8296889: Race condition when cancelling a request
  • JDK-8297075: java/net/httpclient/CancelStreamedBodyTest.java fails with "java.lang.AssertionError: WARNING: tracker for HttpClientImpl(1) has outstanding operations"

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk pull/11193/head:pull/11193
$ git checkout pull/11193

Update a local copy of the PR:
$ git checkout pull/11193
$ git pull https://git.openjdk.org/jdk pull/11193/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 11193

View PR using the GUI difftool:
$ git pr show -t 11193

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/11193.diff

@bridgekeeper
Copy link

bridgekeeper bot commented Nov 16, 2022

👋 Welcome back dfuchs! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk openjdk bot changed the title 8297149 8297149: REDO JDK-8296889: Race condition when cancelling a request Nov 16, 2022
@openjdk openjdk bot added the rfr Pull request is ready for review label Nov 16, 2022
@openjdk
Copy link

openjdk bot commented Nov 16, 2022

@dfuch The following label will be automatically applied to this pull request:

  • net

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the net net-dev@openjdk.org label Nov 16, 2022
@dfuch
Copy link
Member Author

dfuch commented Nov 16, 2022

/issue 8297149 8297075

@openjdk
Copy link

openjdk bot commented Nov 16, 2022

@dfuch This issue is referenced in the PR title - it will now be updated.

Adding additional issue to issue list: 8297075: java/net/httpclient/CancelStreamedBodyTest.java fails with "java.lang.AssertionError: WARNING: tracker for HttpClientImpl(1) has outstanding operations".

@mlbridge
Copy link

mlbridge bot commented Nov 16, 2022

Webrevs

@@ -127,6 +134,15 @@ private void propagateError(Throwable t) {
*/
protected void onCancel() { }

/**
* Called right after the userSubscriber::onSubscribe is called.
Copy link
Member

Choose a reason for hiding this comment

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

Hello Daniel, I suspect this comment will need a change now, since the implementation in this PR now calls onSubscribed before the userSubscriber::onSubscribe.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah! Good catch.

@@ -169,22 +185,23 @@ public CompletionStage<T> getBody() {
public void onSubscribe(Flow.Subscription subscription) {
// race condition with propagateError: we need to wait until
// subscription is finished before calling onError;
synchronized (this) {
subscriptionLock.lock();
Copy link
Member

Choose a reason for hiding this comment

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

More of a question than a review comment - I see that the only place in this class where we were using synchronized is while dealing with the subscribed. The PR replaces the synchronized blocks with a ReentrantLock. Does that have an advantage in context of this code?

Copy link
Member Author

Choose a reason for hiding this comment

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

Well - I am not sure. The code within the block calls onSubscribe on the user subscriber. Theoretically, this should not block, but it might kick off a loop (via calling subscription::request) that may run in the current thread for a while. Using a lock ensures that the waiter will be well-behaved for virtual threads if that ever happens - and no carrier thread will be pinned because of this.

Copy link
Member

Choose a reason for hiding this comment

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

Thank you for that detail. I was suspecting the virtual thread usecase is what might have prompted this but wanted to be sure.

Copy link
Member

@jaikiran jaikiran left a comment

Choose a reason for hiding this comment

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

The latest changes in 60bbce6 look good to me.

@openjdk
Copy link

openjdk bot commented Nov 17, 2022

@dfuch This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8297149: REDO JDK-8296889: Race condition when cancelling a request
8297075: java/net/httpclient/CancelStreamedBodyTest.java fails with "java.lang.AssertionError: WARNING: tracker for HttpClientImpl(1) has outstanding operations"

Reviewed-by: jpai

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 28 new commits pushed to the master branch:

  • 4527dc6: 8297041: Remove the last remnants of sjavac
  • 636040f: 8296405: java/util/concurrent/forkjoin/AsyncShutdownNow.java is too slow
  • 2f728d0: 8295698: AArch64: test/jdk/sun/security/ec/ed/EdDSATest.java failed with -XX:+UseSHA3Intrinsics
  • b9db16a: 8288717: Add a means to close idle connections in HTTP/2 connection pool
  • 9f8b6d2: 8296437: NMT incurs costs if disabled
  • e81359f: 8296170: Refactor stack-locking path in C2_MacroAssembler::fast_unlock()
  • 502fa3e: 8296912: C2: CreateExNode::Identity fails with assert(i < _max) failed: oob: i=1, _max=1
  • 5795c76: 8296222: SwingEventMonitor - installListeners(Component , int ) - CELLEDITOR - bug
  • b9d6e83: 8296906: VMError::controlled_crash crashes with wrong code and address
  • cd9c688: 8276064: CheckCastPP with raw oop input floats below a safepoint
  • ... and 18 more: https://git.openjdk.org/jdk/compare/3eb6d0e2f8d6031cf0fc3ed6eaa6ab203ca72eae...master

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Nov 17, 2022
@dfuch
Copy link
Member Author

dfuch commented Nov 17, 2022

/integrate

@openjdk
Copy link

openjdk bot commented Nov 17, 2022

Going to push as commit 134acab.
Since your change was applied there have been 36 commits pushed to the master branch:

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Nov 17, 2022
@openjdk openjdk bot closed this Nov 17, 2022
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Nov 17, 2022
@openjdk
Copy link

openjdk bot commented Nov 17, 2022

@dfuch Pushed as commit 134acab.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

@dfuch dfuch deleted the CancelRequest-Redo-8297149 branch November 18, 2022 17:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integrated Pull request has been integrated net net-dev@openjdk.org
2 participants