Skip to content

add:gracefull shutdown context based#15

Open
sahilchauhan123 wants to merge 1 commit intocodersgyan:masterfrom
sahilchauhan123:feature/gracefull-shutdown
Open

add:gracefull shutdown context based#15
sahilchauhan123 wants to merge 1 commit intocodersgyan:masterfrom
sahilchauhan123:feature/gracefull-shutdown

Conversation

@sahilchauhan123
Copy link

Implemented Graceful Shutdown System

This implementation provides a complete graceful shutdown mechanism that:

  1. Listens for OS signals:

    • SIGTERM
    • SIGINT
  2. Triggers a shutdown sequence with a configurable timeout.
    This ensures all cleanup operations either complete within the allowed time
    or the shutdown is forced.

  3. Stops accepting new HTTP requests while allowing in-flight requests to finish.

  4. Cleans up application resources in order, including:

    • database connections
    • caches
    • file handles
    • background workers
  5. Returns proper UNIX exit codes based on the received signal:

    • 130 → SIGINT
    • 143 → SIGTERM
      This is useful for Docker, Kubernetes, and CI/CD systems.

Cleanup Registration

The shutdown Register supports both types of cleanup functions:

func() error
func(context.Context) error

Both styles are normalized internally so components can choose either simple
or context-aware cleanup logic without changing the shutdown workflow.

All the things are fully tested

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant