Skip to content

Commit

Permalink
fix the WatchHang() logic
Browse files Browse the repository at this point in the history
  • Loading branch information
equals215 committed Jul 16, 2024
1 parent b0e155b commit 65fedf7
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion internal/pkg/crawl/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,16 +169,20 @@ func (w *Worker) WatchHang() {
time.Sleep(5 * time.Second)
for !w.TryLock() {
if tryLockCounter > 10 && w.state.status != completed {
w.logger.Error("Worker is hanging")
w.logger.Error("Worker is deadlocked, trying to stop it")
spew.Fprint(w.pool.Crawl.Log.Writer(slog.LevelError), w) // This will dump the worker state to the log, this is NOT a good idea in production but it's useful for debugging
w.Stop()
return
}
tryLockCounter++
time.Sleep(1 * time.Second)
}
if w.state.status != idle && time.Since(w.state.lastSeen) > 10*time.Second {
w.logger.Warn("Worker is hanging, stopping it")
spew.Fprint(w.pool.Crawl.Log.Writer(slog.LevelError), w) // This will dump the worker state to the log, this is NOT a good idea in production but it's useful for debugging
w.Unlock()
w.Stop()
return
}
w.Unlock()
}
Expand Down

0 comments on commit 65fedf7

Please sign in to comment.