Skip to content

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

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

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

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

Issue

  • JDK-8304065: HttpServer.stop should terminate immediately if no exchanges are in progress (Bug - P4)

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

Sorry, something went wrong.

@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.

@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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

None yet

2 participants