From b277953e917bb6788c15ea0b6b5f7f68f71b05d0 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 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 --- Koha/BackgroundJob.pm | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Koha/BackgroundJob.pm b/Koha/BackgroundJob.pm index 4ca7603377b..48f9e08dd33 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.34.1