Skip to content

Comments

feat: add context-based timeout configuration for resource lifecycle#49

Merged
appleboy merged 5 commits intomainfrom
timeout
Feb 23, 2026
Merged

feat: add context-based timeout configuration for resource lifecycle#49
appleboy merged 5 commits intomainfrom
timeout

Conversation

@appleboy
Copy link
Member

  • 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>
Copilot AI review requested due to automatic review settings February 23, 2026 05:59
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.Context and 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.

appleboy and others added 4 commits February 23, 2026 14:31
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>
@appleboy appleboy merged commit 3678a63 into main Feb 23, 2026
15 checks passed
@appleboy appleboy deleted the timeout branch February 23, 2026 06:58
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