Skip to content

8304065: HttpServer.stop should terminate immediately if no exchanges are in progress#24467

Closed
eirbjo wants to merge 2 commits intoopenjdk:masterfrom
eirbjo:httpserver-stop-termination
Closed

8304065: HttpServer.stop should terminate immediately if no exchanges are in progress#24467
eirbjo wants to merge 2 commits intoopenjdk:masterfrom
eirbjo:httpserver-stop-termination

Conversation

@eirbjo
Copy link
Contributor

@eirbjo eirbjo commented Apr 5, 2025

Please help review this PR which improves HttpServer::stop termination timing to better fit user expectations.

This PR:

  • Makes ServerImpl::stop continue without delay when there are no active exchanges during shutdown
  • Attempts to interrupt the dispatcher thread before joining it, giving long-living interruptible exchanges a chance to finish early
  • Adds testing for boundary conditions with or without an active exchange, delay occurring before exhange completes and exchange completing before delay.

Additionally, ServerImpl::stop is updated to use System::nanotime instead of System::currentTimeMillis when calculating wait times.

The test relies on timing to assert the order of events. Not perfect, but it seems to work.

(This part of the code base is rather new to me. A bit of hand-holding should be expected when reviewing this PR)


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

Warnings

 ⚠️ Patch contains a binary file (src/java.desktop/share/classes/java/awt/doc-files/BorderLayout-1.gif)
 ⚠️ Patch contains a binary file (src/java.desktop/share/classes/java/awt/doc-files/FlowLayout-1.gif)
 ⚠️ Patch contains a binary file (src/java.desktop/share/classes/java/awt/doc-files/GridBagLayout-1.gif)
 ⚠️ Patch contains a binary file (src/java.desktop/share/classes/java/awt/doc-files/GridBagLayout-2.gif)
 ⚠️ Patch contains a binary file (src/java.desktop/share/classes/java/awt/doc-files/GridLayout-1.gif)
 ⚠️ Patch contains a binary file (src/java.desktop/share/classes/java/awt/doc-files/GridLayout-2.gif)
 ⚠️ Patch contains a binary file (test/hotspot/jtreg/runtime/ClassFile/JsrRewritingTestCase.jar)
 ⚠️ Patch contains a binary file (test/hotspot/jtreg/runtime/ClassFile/testcase.jar)

Issue

  • JDK-8304065: HttpServer.stop should terminate immediately if no exchanges are in progress (Bug - P4) ⚠️ Issue is already resolved. Consider making this a "backport pull request" by setting the PR title to Backport <hash> with the hash of the original commit. See Backports.

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 24467

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

Using diff file

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

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Apr 5, 2025

👋 Welcome back eirbjo! 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
Copy link

openjdk bot commented Apr 5, 2025

❗ This change is not yet ready to be integrated.
See the Progress checklist in the description for automated requirements.

@openjdk
Copy link

openjdk bot commented Apr 5, 2025

@eirbjo 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 Apr 5, 2025
@eirbjo eirbjo force-pushed the httpserver-stop-termination branch from 6fb25d5 to f06c8df Compare April 5, 2025 10:33
@eirbjo eirbjo marked this pull request as ready for review April 5, 2025 11:03
@openjdk openjdk bot added the rfr Pull request is ready for review label Apr 5, 2025
@mlbridge
Copy link

mlbridge bot commented Apr 5, 2025

Webrevs

Comment on lines +237 to +238
long latest = System.nanoTime() + Duration.ofSeconds(delay).toNanos();
while (activeExchanges() > 0 && System.nanoTime() < latest) {
Copy link
Member

Choose a reason for hiding this comment

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

I don't think that works unfortunately. We need something that takes into account that an exchange may have been started but hasn't reached the point where startExchange has been called.

The problem is that exchangeCount is incremeted asynchronously in the ExchangeImpl constructor, and the ExchangeImpl is created by the Exchange::run method - which is run asynchronoously in the executor (submitted by the dispacher thread).

Possibly posting a StopRequested event to the dispatcher thread, and have the dispacther thread switch finished = true when is sees the StopRequested event and notices that allConnections only contains idleConnections (in which case we could also assert that exchangeCount == 0).

Unless I'm not mistaken this is not going to be a trivial fix.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unless I'm not mistaken this is not going to be a trivial fix.

Alright, I'll convert this to a draft PR for now. I may explore solutions, but it seems a full fix could be above my pay grade.

Comment on lines +237 to +238
long latest = System.nanoTime() + Duration.ofSeconds(delay).toNanos();
while (activeExchanges() > 0 && System.nanoTime() < latest) {
Copy link
Member

Choose a reason for hiding this comment

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

Also the arithmetic is dubious since System.nanoTime() + Duration.ofSeconds(delay).toNanos(); could overflow. You never want to compare val1 < val2 - use val2 - val1 > 0 instead.

@eirbjo eirbjo marked this pull request as draft April 7, 2025 14:40
@openjdk openjdk bot removed the rfr Pull request is ready for review label Apr 7, 2025
@dfuch
Copy link
Member

dfuch commented May 20, 2025

Alright, I'll convert this to a draft PR for now. I may explore solutions, but it seems a full fix could be above my pay grade.

@eirbjo: @myankelev has a fix for this issue and will be taking over where you left off. I believe he is reusing the test you provided and will add you as a co-author of the new PR. I hope this is OK with you!

@eirbjo
Copy link
Contributor Author

eirbjo commented May 20, 2025

Alright, I'll convert this to a draft PR for now. I may explore solutions, but it seems a full fix could be above my pay grade.

@eirbjo : @myankelev has a fix for this issue and will be taking over where you left off. I believe he is reusing the test you provided and will add you as a co-author of the new PR. I hope this is OK with you!

@dfuch Absolutely no worries at all!

@openjdk
Copy link

openjdk bot commented May 28, 2025

@eirbjo this pull request can not be integrated into master due to one or more merge conflicts. To resolve these merge conflicts and update this pull request you can run the following commands in the local repository for your personal fork:

git checkout httpserver-stop-termination
git fetch https://git.openjdk.org/jdk.git master
git merge FETCH_HEAD
# resolve conflicts and follow the instructions given by git merge
git commit -m "Merge master"
git push

@openjdk openjdk bot added the merge-conflict Pull request has merge conflict with target branch label May 28, 2025
@vy
Copy link
Contributor

vy commented Jun 19, 2025

#25333 succeeding this PR has already been merged. @eirbjo, shall we close this PR?

@eirbjo
Copy link
Contributor Author

eirbjo commented Jun 19, 2025

#25333 succeeding this PR has already been merged. @eirbjo, shall we close this PR?

Sure, just a draft really but I’ll close it anyhow, not going anywhere :)

@eirbjo eirbjo closed this Jun 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-conflict Pull request has merge conflict with target branch net net-dev@openjdk.org

Development

Successfully merging this pull request may close these issues.

3 participants