fix: EventBus panic on SSE disconnect + JWT secret persistence + recover() guards

- eventbus.go: Fix send-on-closed-channel panic in SubscribeGlobal by
  using a done channel; add recover() in fan-out goroutine; track active
  global subs for proper cleanup on unsubscribe
- config.go: Persist JWT secret to $DATA_DIR/.jwt_secret instead of
  regenerating a random one on every restart (which invalidated all sessions)
- handlers_ws.go: Replace time.After with time.Ticker to fix timer leak in
  SSE keepalive loop
- handlers_jobs.go: Add recover() in fire-and-forget job goroutine; fix nil
  pointer deref when GetByID fails after job creation
- handlers_machines.go: Add recover() in ProbeAllMachines goroutine
- scheduler.go: Add recover() in scheduled job run goroutine
- engine.go: Add recover() in per-machine probe goroutines
This commit is contained in:
2026-07-08 22:38:56 -04:00
parent 1798fc6804
commit 58e7f51ba7
7 changed files with 89 additions and 20 deletions
+5
View File
@@ -83,6 +83,11 @@ func (s *Scheduler) tick() {
ctx := context.Background()
go func(jobID int64, pairID int64, schID int64) {
defer func() {
if r := recover(); r != nil {
slog.Error("scheduler: job run panicked", "job_id", jobID, "panic", r)
}
}()
if err := s.engine.Run(ctx, jobID, pairID); err != nil {
slog.Warn("scheduler: job failed", "job_id", jobID, "error", err)
}