-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
base: master
Are you sure you want to change the base?
Conversation
👋 Welcome back eirbjo! A progress list of the required criteria for merging this PR into |
❗ This change is not yet ready to be integrated. |
6fb25d5
to
f06c8df
Compare
long latest = System.nanoTime() + Duration.ofSeconds(delay).toNanos(); | ||
while (activeExchanges() > 0 && System.nanoTime() < latest) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
long latest = System.nanoTime() + Duration.ofSeconds(delay).toNanos(); | ||
while (activeExchanges() > 0 && System.nanoTime() < latest) { |
There was a problem hiding this comment.
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.
Please help review this PR which improves
HttpServer::stop
termination timing to better fit user expectations.This PR:
ServerImpl::stop
continue without delay when there are no active exchanges during shutdownAdditionally,
ServerImpl::stop
is updated to useSystem::nanotime
instead ofSystem::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
Issue
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