From 6c21a4b0ccbf5ee2c1c246bfd2eee1b856a25375 Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Wed, 13 Nov 2013 14:21:40 +0100 Subject: [PATCH] Bug 11701: Fix C4::Context::Zconn When calling C4::Context::Zconn twice with different parameters, the same ZOOM::Connection object is returned twice (parameters of 2nd call are not used) This patch fixes that. This is in part because the connection cache is keyed on server name only. This patch corrects this by keying on all parameters. TEST PLAN --------- 1) apply patch 2) run koha qa test tools 3) prove -v t/Context.t The unit tests properly triggers the modified routine for testing. Additionally, in hunting for ways it could break, no nested synchronous or asynchronous Zconn's were found. And even if they were, the keying on all parameters should allow it to function properly without messing up the other connection. Signed-off-by: Mark Tompsett Signed-off-by: Jonathan Druart Signed-off-by: Galen Charlton (cherry picked from commit 9b63f0d018ecaa6377124175142826658cb4dd05) Signed-off-by: Fridolin Somers Conflicts: C4/Context.pm --- C4/Context.pm | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/C4/Context.pm b/C4/Context.pm index 282c54fabd..e8ecb3c56a 100644 --- a/C4/Context.pm +++ b/C4/Context.pm @@ -687,14 +687,11 @@ C<$auth> whether this connection has rw access (1) or just r access (0 or NULL) =cut sub Zconn { - my $self=shift; - my $server=shift; - my $async=shift; - my $auth=shift; - my $piggyback=shift; - my $syntax=shift; - if ( defined($context->{"Zconn"}->{$server}) && (0 == $context->{"Zconn"}->{$server}->errcode()) ) { - return $context->{"Zconn"}->{$server}; + my ($self, $server, $async, $auth, $piggyback, $syntax) = @_; + + my $cache_key = join ('::', (map { $_ // '' } ($server, $async, $auth, $piggyback, $syntax))); + if ( defined($context->{"Zconn"}->{$cache_key}) && (0 == $context->{"Zconn"}->{$cache_key}->errcode()) ) { + return $context->{"Zconn"}->{$cache_key}; # No connection object or it died. Create one. }else { # release resources if we're closing a connection and making a new one @@ -703,12 +700,12 @@ sub Zconn { # and make a new one, particularly for a batch job. However, at # first glance it does not look like there's a way to easily check # the basic health of a ZOOM::Connection - $context->{"Zconn"}->{$server}->destroy() if defined($context->{"Zconn"}->{$server}); + $context->{"Zconn"}->{$cache_key}->destroy() if defined($context->{"Zconn"}->{$cache_key}); - $context->{"Zconn"}->{$server} = &_new_Zconn($server,$async,$auth,$piggyback,$syntax); - $context->{ Zconn }->{ $server }->option( + $context->{"Zconn"}->{$cache_key} = &_new_Zconn($server,$async,$auth,$piggyback,$syntax); + $context->{ Zconn }->{$cache_key}->option( preferredRecordSyntax => C4::Context->preference("marcflavour") ); - return $context->{"Zconn"}->{$server}; + return $context->{"Zconn"}->{$cache_key}; } } -- 2.39.5