From ffdafc32c630f3e473cbc2b54a240cd8b59c0b17 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Wed, 24 Apr 2024 23:28:52 +0200 Subject: [PATCH] lib/logstorage: skip scheduled work when stopCh is closed This saves CPU time --- lib/logstorage/storage_search.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/logstorage/storage_search.go b/lib/logstorage/storage_search.go index a0be8ff0f..74e56c7fb 100644 --- a/lib/logstorage/storage_search.go +++ b/lib/logstorage/storage_search.go @@ -133,6 +133,13 @@ func (s *Storage) search(workersCount int, so *genericSearchOptions, stopCh <-ch bs := getBlockSearch() for bsws := range workCh { for _, bsw := range bsws { + select { + case <-stopCh: + // The search has been canceled. Just skip all the scheduled work in order to save CPU time. + continue + default: + } + bs.search(bsw) if bs.br.RowsCount() > 0 { processBlockResult(workerID, &bs.br)