go-graceful-shutdown

Coordinate graceful shutdown of Go services with signal handling and cleanup.

Updated Apr 20, 2026
One-click install
npx skills add https://github.com/vincent119/ai-rules-kit --skill go-graceful-shutdown-vincent119
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: go-graceful-shutdown
Source: https://github.com/vincent119/ai-rules-kit/tree/main/skills/go-graceful-shutdown
Command: npx skills add https://github.com/vincent119/ai-rules-kit --skill go-graceful-shutdown-vincent119

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Go 優雅關機(Graceful Shutdown)模式:Signal 處理、HTTP Server shutdown、gRPC GracefulStop、 Worker/Consumer 停止、Kubernetes 整合、Context 取消機制、資源清理流程。

Core Features & Use Cases

  • 推薦搭配 vincent119/commons/graceful 等套件以統一生命週期管理
  • 提供穩健的生命周期管理,支援 HTTP、gRPC、Background Worker、Queue 等資源的整體關機流程
  • 與 Kubernetes 部署整合,支援 preStop、terminationGracePeriodSeconds 的協調

Quick Start

Configure a Go application to listen for SIGTERM and SIGINT and perform graceful shutdown with HTTP and gRPC servers and cleanup routines.

Frequently Asked Questions about go-graceful-shutdown

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

FAQPage Schema
How do I implement graceful shutdown for HTTP and gRPC servers in Go?

Graceful shutdown for Go HTTP and gRPC servers unifies signal handling with server shutdown methods to safely complete in-flight requests. This coordination ensures background workers and resources clean up properly before the application exits.

What is the best way to coordinate Kubernetes terminationGracePeriodSeconds with Go signal handling?

Coordinating Kubernetes terminationGracePeriodSeconds with Go signal handling involves mapping SIGTERM events to context cancellation and cleanup callbacks. This alignment ensures HTTP and gRPC servers finish active connections within the configured Kubernetes timeout window.

How does context cancellation work during a Go application graceful shutdown?

Context cancellation during Go graceful shutdown propagates stop signals to background workers and queue consumers. This mechanism interrupts pending tasks and triggers resource cleanup routines while aggregating any final lifecycle errors.

Can I stop background workers and queue consumers safely during a Go graceful shutdown?

You can stop background workers and queue consumers safely by integrating them into a unified lifecycle management flow. The process applies cleanup callbacks and timeouts to ensure all active processing halts cleanly without data loss.

Why does my Go service drop in-flight requests when deploying on Kubernetes?

Dropping in-flight requests during Kubernetes deployments happens when Go services lack unified graceful shutdown patterns for SIGTERM handling. Implementing coordinated HTTP server shutdown and gRPC GracefulStop ensures active requests complete before pod termination.

Does graceful shutdown in Go integrate with logging and tracing cleanup?

Graceful shutdown in Go integrates with logging and tracing by executing cleanup callbacks during the termination sequence. This ensures telemetry buffers flush completely and resources release safely before the application process exits.