From 3cb9299647b749bb0215312994832457d00d1ca2 Mon Sep 17 00:00:00 2001 From: Srdjan Date: Mon, 4 Jul 2016 17:08:39 +1200 Subject: [PATCH] Bug 15419 SIP: handle requests with timeout, and refresh dbh if need be Signed-off-by: Alex Buckley --- C4/SIP/Sip/MsgType.pm | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/C4/SIP/Sip/MsgType.pm b/C4/SIP/Sip/MsgType.pm index 4e406e2..512d1e8 100644 --- a/C4/SIP/Sip/MsgType.pm +++ b/C4/SIP/Sip/MsgType.pm @@ -10,6 +10,7 @@ use strict; use warnings; use Exporter; use Sys::Syslog qw(syslog); +use Time::Out qw(timeout); use C4::SIP::Sip qw(:all); use C4::SIP::Sip::Constants qw(:all); @@ -385,7 +386,16 @@ sub handle { print("$last_response\r"); return REQUEST_ACS_RESEND; } - return ( $self->{handler}->( $self, $server ) ); # FIXME + + local $@; + my $ret = timeout (5 => sub { + $self->{handler}->( $self, $server ); + }); + if ($@) { + C4::Context->new_dbh; + $ret = $self->{handler}->( $self, $server ); + } + return $ret; # FIXME: Use of uninitialized value in subroutine entry # Can't use string ("") as a subroutine ref while "strict refs" in use } @@ -1602,7 +1612,15 @@ sub api_auth { if ($branch) { $query->param( branch => $branch ); } - my ( $status, $cookie, $sessionID ) = check_api_auth( $query, { circulate => 1 }, 'intranet' ); + + local $@; + my ( $status, $cookie, $sessionID ) = timeout (5 => sub { + check_api_auth( $query, { circulate => 1 }, 'intranet' ); + }); + if ($@) { + C4::Context->new_dbh; + ( $status, $cookie, $sessionID ) = check_api_auth( $query, { circulate => 1 }, 'intranet' ); + } return $status; } -- 2.1.4