From 429757adf2eb334e4bd781a9c4820ed60f7c0cef Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 10 Mar 2025 10:54:25 +0100 Subject: [PATCH] Bug 34070: Deal with broker connection issues Content-Type: text/plain; charset=utf-8 This patch suggests to deal with connection issues at Koha::BackgroundJob->connect level. It incorrectly returned a Net::Stomp object when the connection failed. With this patch, if the CONNECT does not return a CONNECTED frame then Koha::BackgroundJob->connect returns nothing and the caller is not fooled. It also fixes the about page, we now have: "Using SQL polling (Fallback, Error connecting to RabbitMQ)" instead of "Using RabbitMQ" Signed-off-by: Jonathan Druart Signed-off-by: Marcel de Rooy --- Koha/BackgroundJob.pm | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Koha/BackgroundJob.pm b/Koha/BackgroundJob.pm index 6ab859e614..b81fca6542 100644 --- a/Koha/BackgroundJob.pm +++ b/Koha/BackgroundJob.pm @@ -89,10 +89,16 @@ sub connect { try { $stomp = Net::Stomp->new( { hostname => $hostname, port => $port } ); - $stomp->connect($credentials); + my $connected_frame = $stomp->connect($credentials); + if ( $connected_frame->command ne 'CONNECTED' ) { + my $message = $connected_frame->body; + chomp $message; + warn sprintf "Cannot connect to broker (%s)", $message; + undef $stomp; + } } catch { - warn "Cannot connect to broker " . $_; - $stomp = undef; + warn sprintf "Cannot connect to broker (%s)", $_; + undef $stomp; }; return $stomp; -- 2.39.5