Improve server shutdown process

This commit is contained in:
2025-12-06 19:52:40 +01:00
parent 99927160c2
commit fa311c46ac
4 changed files with 20 additions and 7 deletions

View File

@@ -107,6 +107,12 @@ func Open(config *Config) (*sqliteDB, error) {
func (db *sqliteDB) Close() error {
if db.DB != nil {
log.Println("Closing database connection")
// Checkpoint WAL to merge changes back to main database file
if _, err := db.DB.Exec("PRAGMA wal_checkpoint(TRUNCATE)"); err != nil {
log.Printf("Warning: Failed to checkpoint WAL: %v", err)
}
return db.DB.Close()
}
return nil

View File

@@ -114,11 +114,6 @@ func (im *instanceManager) Shutdown() {
}
wg.Wait()
fmt.Println("All instances stopped.")
// 4. Close database connection
if err := im.db.Close(); err != nil {
log.Printf("Error closing database: %v\n", err)
}
})
}