RFR: 8304065: HttpServer.stop should terminate immediately if no exchanges are in progress
Daniel Jeliński
djelinski at openjdk.org
Wed May 21 06:56:55 UTC 2025
On Tue, 20 May 2025 16:24:30 GMT, Daniel Fuchs <dfuchs at openjdk.org> wrote:
>> HttpServer::stop will terminate the server immidiately after all exhcnages are complete.
>> If the exchanges take longer then the specified delay it will terminate straight after the delay, the same as the previous behaviour.
>>
>> Used to wait until the delay is complete at all times, regardless of the number of active exchanges.
>>
>> Tests based on @eirbjo work, so adding Eirik as a contributor.
>
> src/jdk.httpserver/share/classes/sun/net/httpserver/ServerImpl.java line 252:
>
>> 250: selector.wakeup();
>> 251: long latest = System.nanoTime() + delay * 1000000000L;
>> 252: while (System.nanoTime() < latest) {
>
> This is not correct as `latest` may overflow.
>
> Suggestion:
>
> long start = System.nanoTime();
> while ((System.nanoTime() - start) / 1000_000L < delay ) {
I suppose you could also replace `finished` with a CountDownLatch and get rid of the ugly `delay()` in a loop.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/25333#discussion_r2098500452
More information about the net-dev
mailing list