fix(server): stop the background compaction before the database is closed
MindSift CI & Docker Release / Build, Test in Container & Push (push) Successful in 2m35s

The compaction starts right away in NewServer and could still write to the SQLite files while a
test's temp dir was removed ("directory not empty" on the CI runner, TestWebhookTokenInURLOnlyAPIKey).
Server.Close stops it and waits for a running pass; tests call it before closing the store, and the
server calls it on shutdown before the deferred store.Close. v0.37.1.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
sandrodachandClaude Opus 5.5 committed 2026-11-01 13:16:58 +01:00
1 parent 3fbe015c06
commit c56bd4d943
10 files changed
+43 -6

No files matched your search

+6 -1
View File
@@ -266,9 +266,14 @@ func (s *Server) handleDocLeave(w http.ResponseWriter, r *http.Request) {
const compactionInterval = 6 * time.Hour
func (s *Server) startCompaction() {
defer s.bg.Done()
for {
s.compactOnce()
time.Sleep(compactionInterval)
select {
case <-s.stop:
return
case <-time.After(compactionInterval):
}
}
}