From e6d5aed331a190334e6a105af8b6b00e71d07fa1 Mon Sep 17 00:00:00 2001 From: Michael Peter Christen Date: Sun, 5 Jul 2026 12:13:07 +0200 Subject: fixed shutdown problem --- source/net/yacy/crawler/data/CrawlQueues.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/source/net/yacy/crawler/data/CrawlQueues.java b/source/net/yacy/crawler/data/CrawlQueues.java index fd0fd971e..7d0671047 100644 --- a/source/net/yacy/crawler/data/CrawlQueues.java +++ b/source/net/yacy/crawler/data/CrawlQueues.java @@ -137,8 +137,12 @@ public class CrawlQueues { this.noticeURL.close(); // removed pending requests this.workerQueue.clear(); - // wait for all workers to finish - for (int i = 0; i < this.workerQueue.remainingCapacity(); i++) { + // Send one POISON_REQUEST per worker so that every worker blocked in poll() wakes up and + // terminates its while loop cleanly, without having to be interrupted. + // Note: we iterate over a fixed count (this.worker.length) and not over the shrinking + // remainingCapacity(): each offer() reduces remainingCapacity(), so using it as the loop + // bound would insert only half the required pills and leave the remaining workers blocked. + for (int i = 0; i < this.worker.length; i++) { /* We use the non-blocking offer() function instead of the blocking put() in the unlikely eventual case another thread * added an element to workerQueue during this loop.*/ try { @@ -805,7 +809,10 @@ public class CrawlQueues { profile = null; } } catch (InterruptedException e2) { - ConcurrentLog.logException(e2); + // an interrupt is the expected signal to stop this worker during shutdown or a + // network switch: terminate quietly instead of logging a stack trace. We restore + // the interrupt flag so that any caller up the stack can still observe it. + Thread.currentThread().interrupt(); } } } -- cgit v1.2.3