From 65fedf704930fa2ac74a8285df2d25ca7c0bb894 Mon Sep 17 00:00:00 2001 From: Thomas FOUBERT Date: Mon, 15 Jul 2024 22:36:48 -0400 Subject: [PATCH] fix the WatchHang() logic --- internal/pkg/crawl/worker.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/internal/pkg/crawl/worker.go b/internal/pkg/crawl/worker.go index 722e5f97..194fe4e3 100644 --- a/internal/pkg/crawl/worker.go +++ b/internal/pkg/crawl/worker.go @@ -169,8 +169,9 @@ 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++ @@ -178,7 +179,10 @@ func (w *Worker) WatchHang() { } 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() }