Conversation
Member
appleboy
commented
Feb 23, 2026
- Add configurable timeout settings for initialization and shutdown of database, Redis, cache, server, and audit service
- Document new timeout configuration options and best practices in environment example, README, and configuration guide
- Refactor infrastructure initialization to accept context and apply timeout values from configuration
- Update shutdown jobs to use context-based timeouts and handle forced termination if exceeded
- Ensure Redis and cache initialization and shutdown use context and report errors instead of fatal exit
- Add context-based connection test to Redis cache constructors
- Add context-based Close method to database store with timeout support
- Add tests for timeout configuration, including defaults, environment overrides, invalid values, and reasonable ranges
- Add tests for database Close method to verify context timeout and cancellation handling
- Improve graceful shutdown reliability and observability for all major resources
- Add configurable timeout settings for initialization and shutdown of database, Redis, cache, server, and audit service - Document new timeout configuration options and best practices in environment example, README, and configuration guide - Refactor infrastructure initialization to accept context and apply timeout values from configuration - Update shutdown jobs to use context-based timeouts and handle forced termination if exceeded - Ensure Redis and cache initialization and shutdown use context and report errors instead of fatal exit - Add context-based connection test to Redis cache constructors - Add context-based Close method to database store with timeout support - Add tests for timeout configuration, including defaults, environment overrides, invalid values, and reasonable ranges - Add tests for database Close method to verify context timeout and cancellation handling - Improve graceful shutdown reliability and observability for all major resources Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Adds configurable, context-driven timeout controls across AuthGate’s resource lifecycle (startup + shutdown) to improve graceful shutdown behavior and observability.
Changes:
- Introduces new timeout duration fields in
config.Config(init/close for DB/Redis/cache, server/audit shutdown) and wires them into bootstrap initialization/shutdown paths. - Refactors Redis/cache constructors and bootstrap initialization to accept
context.Contextand perform context-bounded connection health checks. - Adds tests for timeout configuration defaults/env overrides and for database
Close(ctx)behavior; updates docs and examples to describe the new settings.
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| internal/store/sqlite.go | Adds Store.Close(ctx) with timeout support via goroutine + select |
| internal/store/store_test.go | Adds tests for Store.Close(ctx) and post-close health behavior |
| internal/config/config.go | Adds timeout fields to Config and loads them from env with defaults |
| internal/config/timeout_test.go | New tests for timeout defaults, env overrides, invalid values, and ranges |
| internal/cache/rueidis.go | Updates constructor to accept context and ping Redis during init |
| internal/cache/rueidis_aside.go | Updates constructor to accept context and ping Redis during init |
| internal/bootstrap/bootstrap.go | Creates a manager early, passes shutdown context into infra init, adds new shutdown jobs |
| internal/bootstrap/database.go | Uses cfg.DBInitTimeout via context timeout for DB init |
| internal/bootstrap/redis.go | Uses cfg.RedisConnTimeout via context timeout for Redis ping during init |
| internal/bootstrap/cache.go | Adds context/timeouts to metrics cache init; returns errors instead of fatal exits |
| internal/bootstrap/server.go | Uses configurable shutdown timeouts; adds cache/db shutdown jobs with timeout waiting |
| internal/bootstrap/bootstrap_test.go | Updates tests to new initializeMetricsCache signature (ctx + error) |
| docs/CONFIGURATION.md | Documents new timeout env vars and recommended practices |
| docs/DEPLOYMENT.md | Mentions tuning timeouts and links to configuration docs |
| README.md | Highlights configurable timeouts and lifecycle management in project overview |
| .env.example | Adds commented timeout env var examples and recommendations |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
- Replace manual environment variable setup and teardown in tests with t.Setenv for automatic scoping - Add a fast-path check in Store.Close to immediately return a timeout error if the context is already canceled Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.