From 246d62da905f60d5284a2ab770cae99baeb4f1e1 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Fri, 10 Jul 2026 17:07:18 +0100 Subject: [PATCH] Bug 42669: Use exception type check for NoNodes and don't mask real failures Two follow-up fixes from QA review of the previous commit: - Detect Search::Elasticsearch::Error::NoNodes via ref($_) rather than regex-matching the stringified exception, matching the existing pattern already used in about.pl. - Only reset jobs to 'new' for retry when NoNodes is the sole problem. If a genuine indexing error also occurred in the same batch, record the batch as 'failed' instead of silently discarding that error via the NoNodes retry path. Signed-off-by: Lisette Scheer Signed-off-by: Lucas Gass --- misc/workers/es_indexer_daemon.pl | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/misc/workers/es_indexer_daemon.pl b/misc/workers/es_indexer_daemon.pl index 9b7fa109de..c621cc05dc 100755 --- a/misc/workers/es_indexer_daemon.pl +++ b/misc/workers/es_indexer_daemon.pl @@ -253,7 +253,7 @@ sub commit { $auth_indexer->update_index( \@auth_chunk ); } catch { $logger->warn( sprintf "Update of elastic index failed with: %s", $_ ); - if ( "$_" =~ /NoNodes/ ) { + if ( ref($_) eq 'Search::Elasticsearch::Error::NoNodes' ) { $no_nodes = 1; $auth_indexer = Koha::SearchEngine::Indexer->new( { index => $Koha::SearchEngine::AUTHORITIES_INDEX } ); @@ -270,7 +270,7 @@ sub commit { $biblio_indexer->update_index( \@bib_chunk ); } catch { $logger->warn( sprintf "Update of elastic index failed with: %s", $_ ); - if ( "$_" =~ /NoNodes/ ) { + if ( ref($_) eq 'Search::Elasticsearch::Error::NoNodes' ) { $no_nodes = 1; $biblio_indexer = Koha::SearchEngine::Indexer->new( { index => $Koha::SearchEngine::BIBLIOS_INDEX } ); @@ -281,9 +281,11 @@ sub commit { } } - if ($no_nodes) { + if ( $no_nodes && $index_ok ) { - # ES is unreachable — reset jobs to 'new' so they are retried after reconnection + # ES is unreachable, and no other error occurred — reset jobs to 'new' so they are retried + # after reconnection. If a genuine indexing error also occurred, fall through to record + # the batch as 'failed' instead, so that error isn't masked by the retry. $logger->warn("Elasticsearch unavailable (NoNodes), resetting jobs for retry"); $jobs->update( {