Repository navigation
Conversation
HttpServer.stop(delay) can wait out the full delay with nothing in flight: when a client closes an idle keep-alive connection just before stop, the JDK never counts its finished latch down (JDK 25 ServerImpl). OpenApiServer now counts in-flight requests with a filter on every context it creates. stop(delay) closes the listener at once through a background HttpServer.stop(delay), waits on the counter for at most the delay, then calls HttpServer.stop(0). Later and concurrent stop calls wait for the first. inFlightRequests() exposes the count.
thced
marked this pull request as ready for review
October 15, 2026 17:59
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
OpenApiServer.stop(delay)could wait out the full delay with no request in flight. In the JDK'sHttpServer(ServerImpl, JDK 25), if a client closes an idle keep-alive connection just beforestop, the connection is cleaned up but the finished latch is never counted down.stopthen sleeps the whole delay. A plain-JDK repro stalls in about 1 of 4 rounds. Consumers see it as slow shutdowns and 5 s stalls in tests.OpenApiServernow counts in-flight requests itself:InFlightCounteris a filter, first on every context the server creates. It counts each request through its handler andafterResponserunnables, with the decrement infinally.stop(delay):HttpServer.stop(delay)on a virtual thread, so the listener closes at once and new connections are refused as before;delay;HttpServer.stop(0), which releases the JDK's latch.Open keep-alive connections are still served until the JDK sees no exchange in flight, as before.
Repeated
stop: later and concurrent calls wait for the first one to finish. A failure in the first call reaches them as anIllegalStateException.inFlightRequests()is new public API that exposes the count, so callers can build their own drain.Notes
feat: new public API, and a secondstopcall now waits for the first.GracefulStopIT(11 tests, about 3 s):stop;OpenApiServerIT$Filtershang is unrelated to this change. Onemvn verifyrun hung inpostFilterShortStringMatchesNoBranchReturns400. Looping the same scenario hangs onmasterat the same rate (3 in 12,000, against 1 in 12,000 on this branch). The cause: the server binds the wildcard address on a random port, and another local process can already hold that port on 127.0.0.1, solocalhostreaches it instead. A fix would be a separate change: tests bind and call127.0.0.1.