[Koha-patches] [PATCH] Bug 15419 SIP: call auth() subs with timeout, and refresh dbh if need be

Srdjan srdjan at catalyst.net.nz
Mon Jul 4 07:16:58 CEST 2016


---
 C4/SIP/ILS/Patron.pm  | 11 +++++++++--
 C4/SIP/Sip/MsgType.pm | 11 ++++++++++-
 2 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/C4/SIP/ILS/Patron.pm b/C4/SIP/ILS/Patron.pm
index 93b6c54..c3d348d 100644
--- a/C4/SIP/ILS/Patron.pm
+++ b/C4/SIP/ILS/Patron.pm
@@ -14,6 +14,7 @@ use Carp;
 
 use Sys::Syslog qw(syslog);
 use Data::Dumper;
+use Time::Out qw(timeout);
 
 use C4::Debug;
 use C4::Context;
@@ -199,9 +200,15 @@ sub check_password {
     # If the record has a NULL password, accept '' as match
     return $pwd eq q{} unless $self->{password};
 
-    my $dbh = C4::Context->dbh;
     my $ret = 0;
-    ($ret) = checkpw( $dbh, $self->{userid}, $pwd, undef, undef, 1 ); # dbh, userid, query, type, no_set_userenv
+    local $@;
+    ($ret) = timeout (5 => sub {
+        #        dbh, userid, query, type, no_set_userenv
+        checkpw( C4::Context->dbh, $self->{userid}, $pwd, undef, undef, 1 );
+    });
+    if ($@) {
+        ($ret) = checkpw( C4::Context->new_dbh, $self->{userid}, $pwd, undef, undef, 1 );
+    }
     return $ret;
 }
 
diff --git a/C4/SIP/Sip/MsgType.pm b/C4/SIP/Sip/MsgType.pm
index 787449b..e8a4669 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);
@@ -1607,7 +1608,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.7.4


More information about the Koha-patches mailing list