fix: 优雅停机停等任务 goroutine,根治 TempDir 清理竞态
新增 Server.Close / Engine.StopAll:取消 ctx 后依次等 side-flusher、 后台循环、各任务 planner/worker、归档 worker 退出;测试用 defer s.Close() 在清理前排空 goroutine,遂把 tempDir 兜底改回 t.TempDir() 并删除 helper。
This commit is contained in:
1 parent
f8454d310b
commit
98515a3974
10 files changed
+75
-6
No files matched your search
@@ -290,6 +290,27 @@ func (e *Engine) StopTask(taskID string) {
|
||||
e.deleteMu.Unlock()
|
||||
}
|
||||
|
||||
// StopAll cancels every live task runtime and waits for its planner, worker and
|
||||
// deadline goroutines to return. Used on server shutdown (Server.Close): unlike
|
||||
// StopTask it does not purge the per-task Engine maps — the process/Server is going
|
||||
// away — it only makes sure no task goroutine survives to keep writing (e.g., into
|
||||
// a test's data dir while Go's t.TempDir cleanup is removing it). Cancelling the
|
||||
// server context already signals these loops; this blocks until they have exited.
|
||||
func (e *Engine) StopAll() {
|
||||
e.runtimeMu.Lock()
|
||||
rts := make([]*taskRuntime, 0, len(e.runtimes))
|
||||
for _, rt := range e.runtimes {
|
||||
rts = append(rts, rt)
|
||||
}
|
||||
e.runtimeMu.Unlock()
|
||||
for _, rt := range rts {
|
||||
rt.cancel()
|
||||
}
|
||||
for _, rt := range rts {
|
||||
rt.wg.Wait()
|
||||
}
|
||||
}
|
||||
|
||||
// cancelExec cancels a task's current per-task exec context (any in-flight
|
||||
// planner.Plan / worker.Execute), if present. Shared by Pause and the settle
|
||||
// sequence's hard-drain backstop.
|
||||
|
||||
Reference in new issue
Block a user