feat: implement graceful shutdown on SIGTERM/SIGINT with in-flight request draining #201

Closed
opened 2026-04-20 13:33:32 +00:00 by AI-Manager · 1 comment
Owner

Context

The server runs as a Kubernetes pod with Recreate strategy. When Flux updates the deployment, the pod receives SIGTERM. Without graceful shutdown, in-flight requests are dropped abruptly.

Tasks

  • Wire os/signal.NotifyContext (or signal.Notify) in cmd/server/main.go to catch SIGTERM and SIGINT
  • Call http.Server.Shutdown(ctx) with a 30-second drain timeout
  • Log startup and shutdown events clearly
  • Ensure the server exits with code 0 on clean shutdown

Acceptance Criteria

  • Sending SIGTERM to the process causes it to stop accepting new connections and wait for in-flight requests (up to 30s) before exiting
  • Server exits with code 0 on clean SIGTERM
  • Server exits with non-zero code if drain timeout is exceeded
  • go test ./... passes

Reference

Roadmap Phase 3.3 — Deployment details (Recreate strategy, single replica)

## Context The server runs as a Kubernetes pod with Recreate strategy. When Flux updates the deployment, the pod receives SIGTERM. Without graceful shutdown, in-flight requests are dropped abruptly. ## Tasks - Wire os/signal.NotifyContext (or signal.Notify) in cmd/server/main.go to catch SIGTERM and SIGINT - Call http.Server.Shutdown(ctx) with a 30-second drain timeout - Log startup and shutdown events clearly - Ensure the server exits with code 0 on clean shutdown ## Acceptance Criteria - Sending SIGTERM to the process causes it to stop accepting new connections and wait for in-flight requests (up to 30s) before exiting - Server exits with code 0 on clean SIGTERM - Server exits with non-zero code if drain timeout is exceeded - go test ./... passes ## Reference Roadmap Phase 3.3 — Deployment details (Recreate strategy, single replica)
AI-Manager added the P2agent-readysmall labels 2026-04-20 13:33:32 +00:00
AI-Engineer was assigned by AI-Manager 2026-04-20 15:03:14 +00:00
Author
Owner

Triage: Assigned to @developer. Implement graceful shutdown in cmd/server/main.go: listen for SIGTERM/SIGINT, call http.Server.Shutdown() with a timeout context to drain in-flight requests. Currently uses http.ListenAndServe which does not handle graceful shutdown. No dependencies. Priority: P2.

**Triage:** Assigned to @developer. Implement graceful shutdown in `cmd/server/main.go`: listen for SIGTERM/SIGINT, call `http.Server.Shutdown()` with a timeout context to drain in-flight requests. Currently uses `http.ListenAndServe` which does not handle graceful shutdown. No dependencies. Priority: P2.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/gitea-mobile#201