On Fri, 2020-08-07 at 20:04 +0200, Niklas Lochschmidt wrote: > I am trying to use the graceful shutdown of HttpServer server for > http4k, using HttpCore 4.4.13 and 5.0.1. I am creating the server > simply > using `ServerBootstrap.bootstrap().register(...).create()` and > shutting > down with `shutdown(5, TimeUnit.SECONDS)` and > `close(CloseMode.GRACEFUL)` respectively. Here is what I am seeing: > > - When the server has never been requested it shuts down instantly > ✔️ > - When the server has been requested by a client without keep-alive > it > shuts down instantly ✔️ > - When the server has been requested by a client with keep-alive and > the > request is in-flight during shutdown it shuts down as soon as the > request is done ✔️ > > The problem is, when I connected with a client that uses keep-alive, > and > the request has been handled by the server and now the client is > holding > the connection open, then when I shutdown the server, the server > will > take the whole grace period to shutdown at which point the keep- > alive > connections are finally being force-closed. > > Is it possible to somehow speed up the shutdown also in this case > without terminating in-flight requests? Is there maybe a workaround > to > terminate all idle connections with keep-alives immediately before > shutdown? >
The problem is there is no way of reliably testing whether a connection is idle or not, as connections can become active immediately after passing inactivity test. What could be a reasonable solution in many cases is to reduce the default grace period timeout. This will make the server await connection termination for 1 second instead of 5 seconds. ``` HttpServer server = ServerBootstrap.bootstrap().create(); server.initiateShutdown(); server.awaitTermination(TimeValue.ofSeconds(1)); server.close(CloseMode.IMMEDIATE); ``` Having said that there might be a better way to detect idle server-side connections as well. Feel free to raise a request in JIRA if you want me to look into that. Oleg --------------------------------------------------------------------- To unsubscribe, e-mail: httpclient-users-unsubscr...@hc.apache.org For additional commands, e-mail: httpclient-users-h...@hc.apache.org