From b7f6afb12645f576be65c0619d86211034ffa3b1 Mon Sep 17 00:00:00 2001 From: Olli-Antti Kivilahti Date: Mon, 2 Jan 2017 13:01:02 +0200 Subject: [PATCH] Bug 17833 - Memcached silently fails to _initilize_memcached() on the second time it is invoked When _initilize_memcached() is called the first time, it sets the 'ismemcached'-key and returns 1. When _initilize_memcached() is called the second time, the 'ismemcached'-key already exists and '' is returned (this default to False in Perl). Koha thinks that memcached is not in use and decides to use some other caching mechanism instead. Cache::Memcached::Fast returns undef on server error: https://metacpan.org/pod/Cache::Memcached::Fast#add Koha MUST listen to undefined, instead of False to define whether or not memcached is properly working. Also added simple helpful diagnostics to help identify and log when this memcached server connection problem arises. --- Koha/Cache.pm | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Koha/Cache.pm b/Koha/Cache.pm index 80ff1ca..80bff6b 100644 --- a/Koha/Cache.pm +++ b/Koha/Cache.pm @@ -146,9 +146,21 @@ sub _initialize_memcached { utf8 => 1, } ); + # Ensure we can actually talk to the memcached server my $ismemcached = $memcached->set('ismemcached','1'); - return $self unless $ismemcached; + if (defined($ismemcached)) { #If value is defined, memcached is alive + if ($ismemcached) { #Value is true so operation succeeded + #Ok + } + else { #Value is False, but still defined, so the 'ismemcached'-key already exists. + #Ok, while nothing happened + } + } + else { #Value is undefined, so there was an error with the server, or the connection to it + warn "Connection to the memcached servers '@servers' failed. Are the unix socket permissions set properly? Is the host reachable?"; + return $self; + } $self->{'memcached_cache'} = $memcached; return $self; } -- 2.7.4