[PR #482] [MERGED] refactor: graceful shutdown for server #778

Open
opened 2025-10-09 16:57:03 +03:00 by OVERLORD · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/pocket-id/pocket-id/pull/482
Author: @ItalyPaleAle
Created: 4/25/2025
Status: Merged
Merged: 4/28/2025
Merged by: @stonith404

Base: mainHead: graceful-server-shutdown


📝 Commits (3)

  • 58beec2 refactor: graceful shutdown for server
  • 2c8c0ae Lint
  • ac37aaa Merge branch 'main' into graceful-server-shutdown

📊 Changes

10 files changed (+207 additions, -88 deletions)

View changed files

📝 backend/internal/bootstrap/application_images_bootstrap.go (+7 -3)
📝 backend/internal/bootstrap/bootstrap.go (+3 -1)
📝 backend/internal/bootstrap/router_bootstrap.go (+74 -13)
📝 backend/internal/job/api_key_expiry_job.go (+2 -10)
📝 backend/internal/job/db_cleanup_job.go (+9 -14)
📝 backend/internal/job/file_cleanup_job.go (+2 -10)
backend/internal/job/job.go (+0 -29)
📝 backend/internal/job/ldap_job.go (+6 -8)
backend/internal/job/scheduler.go (+64 -0)
backend/internal/utils/signals/signal.go (+40 -0)

📄 Description

Initial work on graceful shutdown, for now focused on the Gin server.

Implements the graceful shutdown pattern, by capturing SIGINT or SIGTERM signals, and asking the Gin server to drain all active requests before shutting down. This makes it so requests aren't interrupted while in-flight, if possible.

Additionally, includes rudimental graceful shutdown for the job scheduler, although this is not complete yet (the app doesn't wait for the scheduler to be shut down before exiting).

As part of the work on the scheduler, there's now a single gocron scheduler created, instead of 4. This is useful because each gocron scheduler spawns its own set of goroutines in background.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/pocket-id/pocket-id/pull/482 **Author:** [@ItalyPaleAle](https://github.com/ItalyPaleAle) **Created:** 4/25/2025 **Status:** ✅ Merged **Merged:** 4/28/2025 **Merged by:** [@stonith404](https://github.com/stonith404) **Base:** `main` ← **Head:** `graceful-server-shutdown` --- ### 📝 Commits (3) - [`58beec2`](https://github.com/pocket-id/pocket-id/commit/58beec22ee8d2d6289347bd6fd1dd8caa26c0169) refactor: graceful shutdown for server - [`2c8c0ae`](https://github.com/pocket-id/pocket-id/commit/2c8c0ae4f6e8b52b445c16d71756fe60967ab34f) Lint - [`ac37aaa`](https://github.com/pocket-id/pocket-id/commit/ac37aaaa568901e64dd915292995833aba84ffd1) Merge branch 'main' into graceful-server-shutdown ### 📊 Changes **10 files changed** (+207 additions, -88 deletions) <details> <summary>View changed files</summary> 📝 `backend/internal/bootstrap/application_images_bootstrap.go` (+7 -3) 📝 `backend/internal/bootstrap/bootstrap.go` (+3 -1) 📝 `backend/internal/bootstrap/router_bootstrap.go` (+74 -13) 📝 `backend/internal/job/api_key_expiry_job.go` (+2 -10) 📝 `backend/internal/job/db_cleanup_job.go` (+9 -14) 📝 `backend/internal/job/file_cleanup_job.go` (+2 -10) ➖ `backend/internal/job/job.go` (+0 -29) 📝 `backend/internal/job/ldap_job.go` (+6 -8) ➕ `backend/internal/job/scheduler.go` (+64 -0) ➕ `backend/internal/utils/signals/signal.go` (+40 -0) </details> ### 📄 Description Initial work on graceful shutdown, for now focused on the Gin server. Implements the [graceful shutdown pattern](https://www.freecodecamp.org/news/graceful-shutdowns-k8s-go/), by capturing SIGINT or SIGTERM signals, and asking the Gin server to drain all active requests before shutting down. This makes it so requests aren't interrupted while in-flight, if possible. Additionally, includes _rudimental_ graceful shutdown for the job scheduler, although this is not complete yet (the app doesn't wait for the scheduler to be shut down before exiting). As part of the work on the scheduler, there's now a single gocron scheduler created, instead of 4. This is useful because each gocron scheduler spawns its own set of goroutines in background. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
OVERLORD added the pull-request label 2025-10-09 16:57:03 +03:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/pocket-id-pocket-id-2#778