graceful-shutdown

Configures graceful shutdown for Spring Boot services to drain in-flight requests during Kubernetes pod termination.

Updated Jun 25, 2026
One-click install
npx skills add https://github.com/oriddd/ai-toolkit --skill graceful-shutdown-oriddd
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: graceful-shutdown
Source: https://github.com/oriddd/ai-toolkit/tree/main/copilot/public/skills/graceful-shutdown
Command: npx skills add https://github.com/oriddd/ai-toolkit --skill graceful-shutdown-oriddd

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Rolling deployments and pod terminations in Kubernetes often cause 5xx spikes, dropped requests, and stuck transactions when a Spring Boot service is killed mid-request. This Skill wires graceful shutdown across the HTTP server, async executors, message consumers, and outbound clients so in-flight work completes before the process exits. ## Core Features & Use Cases - Spring Boot graceful shutdown: Enables server.shutdown=graceful with a shutdown-phase timeout so in-flight HTTP requests complete before the connector closes. - Kubernetes termination contract: Aligns terminationGracePeriodSeconds, a preStop sleep hook, and Spring's timeout so ingress and kube-proxy drain endpoints before shutdown begins. - Executor and consumer draining: Configures TaskExecutor wait-on-shutdown, Kafka and RabbitMQ listener shutdown timeouts, and @PreDestroy cleanup for native HTTP clients. - Use Case: When a deployment shows 5xx spikes during kubectl rollout restart, apply this Skill to eliminate dropped requests and validate the fix with a k6 load test during a rolling update. ## Quick Start Apply the graceful-shutdown skill to this Spring Boot service and configure the application YAML, Kubernetes deployment, and executors for clean pod termination.

Frequently Asked Questions about graceful-shutdown

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I enable graceful shutdown in Spring Boot?

Set server.shutdown=graceful and spring.lifecycle.timeout-per-shutdown-phase=30s in application YAML. Spring stops accepting new HTTP requests, lets in-flight ones finish within the timeout, then closes the connector.

How to configure Kubernetes terminationGracePeriodSeconds for Spring Boot?

Set terminationGracePeriodSeconds greater than Spring's shutdown timeout plus the preStop delay, for example 60 seconds with a 30s Spring timeout and a 5s preStop sleep. The preStop hook gives kube-proxy and ingress time to remove the endpoint before shutdown starts.

Does Kafka listener drain messages during Spring Boot shutdown?

Yes, set spring.kafka.listener.shutdown-timeout to a value like 20s so the container finishes the in-flight record and commits its offset before exit. RabbitMQ uses spring.rabbitmq.listener.simple.shutdown-timeout similarly.

Why do I get 5xx errors during Kubernetes rolling updates?

Pods are terminated mid-request when graceful shutdown is disabled or the ingress still routes traffic to a terminating pod. Enabling server.shutdown=graceful plus a preStop sleep lets endpoints drain before the process stops accepting requests.

How do I shut down a custom ExecutorService in Spring Boot?

Register a @PreDestroy method that calls shutdown(), then awaitTermination with a timeout, and finally shutdownNow() if the timeout expires. For Spring TaskExecutors, set setWaitForTasksToCompleteOnShutdown(true) and setAwaitTerminationSeconds(20).