With 2.3 a graceful shutdown has been introduced. After a shutdown has been initiated, the web server will reject new requests with HTTP 503. This is unfortunately something that the clients will notice (for requests sent after the shutdown has been initiated). I propose that we add logic in the shutdown hook that will trip the readiness probe to REFUSING_TRAFFIC and then wait for a configurable amount of time (default would be 0 so that it behaves as it does right now). During that wait-time, new requests will be accepted and processed but the /actuator/health/readiness will return 503. This will allow a load-balancer to notice that a node is going down and stop forwarding traffic to it. After the wait time we will proceed with the current graceful shutdown (closing the application context) - however, no new requests will arrive (and fail with 503) as we have been taken out of the pool.
That of course is easily done in the application but I guess other users might also need it so it would be nice to have it in spring-boot.
PS. I tried doing that with a smartlifecycle bean but it gets called after the shutdown has terminated the management connector and I did not like that. I think that the right place is the shutdown hook and the change would be something like:
AvailabilityChangeEvent.publish(ctx, ReadinessState.REFUSING_TRAFFIC);
try {
Thread.sleep(20_000); // make configurable
} catch (final InterruptedException e) {
Thread.currentThread().interrupt();
}
just before closing the application context. I have not considered what should happen in case of context refresh.
Comment From: bclozel
This is a duplicate of #20995. I'm closing this issue as a result. Thanks!