Fix shutdown handling and optimize SQLite settings
- Fix Ctrl-C shutdown by using fx.Shutdowner instead of just canceling context - Pass context from fx lifecycle to rw.Run() for proper cancellation - Adjust WAL settings: checkpoint at 50MB, max size 100MB - Reduce busy timeout from 30s to 2s to fail fast on lock contention This should fix the issue where Ctrl-C doesn't cause shutdown and improve database responsiveness under heavy load.
This commit is contained in:
@@ -58,26 +58,25 @@ func CLIEntry() {
|
||||
app := fx.New(
|
||||
getModule(),
|
||||
fx.StopTimeout(shutdownTimeout), // Allow 60 seconds for graceful shutdown
|
||||
fx.Invoke(func(lc fx.Lifecycle, rw *RouteWatch, logger *logger.Logger) {
|
||||
fx.Invoke(func(lc fx.Lifecycle, rw *RouteWatch, logger *logger.Logger, shutdowner fx.Shutdowner) {
|
||||
lc.Append(fx.Hook{
|
||||
OnStart: func(_ context.Context) error {
|
||||
OnStart: func(ctx context.Context) error {
|
||||
// Start debug stats logging
|
||||
go logDebugStats(logger)
|
||||
|
||||
// Handle shutdown signals
|
||||
sigCh := make(chan os.Signal, 1)
|
||||
signal.Notify(sigCh, os.Interrupt, syscall.SIGTERM)
|
||||
|
||||
go func() {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
// Handle shutdown signals
|
||||
sigCh := make(chan os.Signal, 1)
|
||||
signal.Notify(sigCh, os.Interrupt, syscall.SIGTERM)
|
||||
|
||||
go func() {
|
||||
<-sigCh
|
||||
logger.Info("Received shutdown signal")
|
||||
cancel()
|
||||
}()
|
||||
<-sigCh
|
||||
logger.Info("Received shutdown signal")
|
||||
if err := shutdowner.Shutdown(); err != nil {
|
||||
logger.Error("Failed to shutdown gracefully", "error", err)
|
||||
}
|
||||
}()
|
||||
|
||||
go func() {
|
||||
if err := rw.Run(ctx); err != nil {
|
||||
logger.Error("RouteWatch error", "error", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user