Graceful Shutdown — Concept Check
Questions on Graceful Shutdown. On SIGTERM, stop accepting new requests, drain in-flight requests within a configurable timeout, then close connections — Spring Boot handles this via server.shutdown=graceful.
Questions in this quiz
8 questions on Graceful Shutdown — Concept Check. Work through them here, then start the quiz to answer them and see your score.
1.A Spring Boot service is configured with `server.shutdown=graceful` and `spring.lifecycle.timeout-per-shutdown-phase=20s`. Kubernetes sends a SIGTERM with `terminationGracePeriodSeconds` set to 30 seconds. What happens if an in-flight request takes 25 seconds to complete?
- AThe service waits indefinitely for the request to complete.
- BThe request is terminated after 20 seconds.
- CThe request completes successfully before SIGKILL.
- DThe request completes successfully after SIGKILL.
2.During a rolling deploy, a Kubernetes pod with a readiness probe is shutting down. What role does the `preStop` hook play in graceful shutdown?
- AIt ensures new requests are accepted during shutdown.
- BIt deregisters the pod from the load balancer.
- CIt delays SIGTERM to allow the load balancer to update.
- DIt immediately stops all in-flight requests.
3.You notice that a Spring Kafka consumer stops abruptly during shutdown. Which configuration might be missing?
- ASetting `spring.lifecycle.timeout-per-shutdown-phase`.
- BUsing `server.shutdown=graceful` in application.properties.
- CConfiguring `terminationGracePeriodSeconds` in Kubernetes.
- DImplementing `@PreDestroy` in the consumer.
4.A developer believes that setting `server.shutdown=graceful` in Spring Boot will automatically handle all aspects of graceful shutdown, including database connections and message consumers. What is the flaw in this belief?
- AIt requires a custom shutdown script to work.
- BIt handles everything, so there is no flaw.
- CIt only handles HTTP requests, not database or message consumers.
- DIt only works if `terminationGracePeriodSeconds` is set to 0.
5.A service is configured with a `preStop` hook that sleeps for 5 seconds. Kubernetes sends a SIGTERM at t=0. When does Spring Boot stop accepting new requests?
- AAt t=30, after SIGKILL.
- BAt t=0, immediately after SIGTERM.
- CAt t=5, after the `preStop` sleep.
- DAt t=10, after the drain window.
6.What happens if `spring.lifecycle.timeout-per-shutdown-phase` is set longer than `terminationGracePeriodSeconds` in Kubernetes?
- AThe application will gracefully handle all requests regardless of the timeout.
- BThe Kubernetes setting is ignored in favor of Spring Boot's configuration.
- CThe application will not receive a SIGTERM signal.
- DThe application may be forcefully terminated before completing in-flight requests.
7.A developer claims that setting `terminationGracePeriodSeconds` to 0 will ensure the fastest shutdown. What is the issue with this approach?
- AIt ensures the longest possible shutdown time.
- BIt only affects startup time, not shutdown.
- CIt is necessary for graceful shutdown.
- DIt prevents graceful shutdown, leading to abrupt termination.
8.How does Spring Kafka's `ConcurrentMessageListenerContainer` contribute to graceful shutdown?
- AIt requires manual intervention to stop during shutdown.
- BIt automatically stops the container on `SmartLifecycle.stop()`.
- CIt continues processing messages indefinitely during shutdown.
- DIt only stops if `server.shutdown=graceful` is set.