{"id":19114470,"url":"https://github.com/pinebit/go-graceful-shutdown","last_synced_at":"2026-06-17T18:05:39.402Z","repository":{"id":90867419,"uuid":"449180737","full_name":"pinebit/go-graceful-shutdown","owner":"pinebit","description":"A dummy server that implements a graceful shutdown pattern","archived":false,"fork":false,"pushed_at":"2022-01-18T07:33:11.000Z","size":6,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-22T12:12:20.176Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pinebit.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-01-18T07:19:12.000Z","updated_at":"2022-01-18T07:33:14.000Z","dependencies_parsed_at":null,"dependency_job_id":"12c25e42-2c6e-4c7e-9bcd-772586d53fba","html_url":"https://github.com/pinebit/go-graceful-shutdown","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/pinebit/go-graceful-shutdown","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pinebit%2Fgo-graceful-shutdown","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pinebit%2Fgo-graceful-shutdown/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pinebit%2Fgo-graceful-shutdown/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pinebit%2Fgo-graceful-shutdown/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pinebit","download_url":"https://codeload.github.com/pinebit/go-graceful-shutdown/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pinebit%2Fgo-graceful-shutdown/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34459702,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-17T02:00:05.408Z","response_time":127,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-09T04:42:19.833Z","updated_at":"2026-06-17T18:05:39.383Z","avatar_url":"https://github.com/pinebit.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go-graceful-shutdown\n\nThis project demonstrates a pattern for graceful server shutdown in Go. It was inspired by this\narticle: https://rudderstack.com/blog/implementing-graceful-shutdown-in-go\n\nThe sample server maintains:\n\n- a connection to postgres database\n- an HTTP webserver\n- a few long-running services using PG connection\n\nUpon startup:\n\n- hooks on signals: SIGINT and SIGTERM to initiate a shutdown flow\n- creates a global context that will be cancelled in case of shutdown\n- the server connects to postgres database \"test\"\n- starts HTTP webserver\n- spawns a few goroutines that represent long-running tasks\n- main thread remains blocked until one of the signals caught\n\nOnce one of the signals caught:\n\n- it cancels the global context\n- all child components will finish executing because of ctx.Done()\n- the main thread unblocks receiving the error (if any)\n- database is closing as the last step of shutdown\n\nEdge cases:\n\n- if a termination signal received upon startup sequence, it cancels the global context, and then newly creating\n  components should start and stop pretty much immediately.\n- if a termination signal received during shutdown sequence, it will be ignored.\n- because SIGKILL cannot be handled, killing the server process will result in inconsistent state.\n\n## How to build and run\n\n- have a postgres instance up and running on your machine\n- create an empty DB \"test\"\n- `go run .`\n- try terminating the app by Ctrl+C (or by sending SIGINT or SIGTERM from terminal)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpinebit%2Fgo-graceful-shutdown","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpinebit%2Fgo-graceful-shutdown","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpinebit%2Fgo-graceful-shutdown/lists"}