Bug 13431 [QA Follow-up]: Shared FastMmap file causes issues
authorJacek Ablewicz <abl@biblos.pk.edu.pl>
Tue, 30 Dec 2014 09:30:30 +0000 (10:30 +0100)
committerTomas Cohen Arazi <tomascohen@gmail.com>
Wed, 11 Feb 2015 13:18:56 +0000 (10:18 -0300)
1) Removed 'use C4::Context;' because it can lead to introduction
of circular reference in the near future
2) Put fastmmap initialization code into an eval {} block, to catch
various kinds of errors which can still occur during it's init in
some [less usual] Koha setups and/or more unusual circumstances
3) Do not include UID in the sharefile name (it will be constructed
using namespace + database name + database host instead).

Test plan addendum:

   s/and UID//

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Jonathan Druart <jonathan.druart@biblibre.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
Koha/Cache.pm

index 5611c52..f4765b2 100644 (file)
@@ -40,7 +40,6 @@ use warnings;
 use Carp;
 use Module::Load::Conditional qw(can_load);
 use Koha::Cache::Object;
-use C4::Context;
 
 use base qw(Class::Accessor);
 
@@ -161,16 +160,28 @@ sub _initialize_memcached {
 
 sub _initialize_fastmmap {
     my ($self) = @_;
-    my $share_file = join( '-',
-        "/tmp/sharefile-koha", $self->{'namespace'},
-        C4::Context->config('hostname'), C4::Context->config('database'),
-        "" . getpwuid($>) );
-
-    $self->{'fastmmap_cache'} = Cache::FastMmap->new(
-        'share_file'  => $share_file,
-        'expire_time' => $self->{'timeout'},
-        'unlink_on_exit' => 0,
-    );
+    my ($cache, $share_file);
+
+    # Temporary workaround to catch fatal errors when: C4::Context module
+    # is not loaded beforehand, or Cache::FastMmap init fails for whatever
+    # other reason (e.g. due to permission issues - see Bug 13431)
+    eval {
+        $share_file = join( '-',
+            "/tmp/sharefile-koha", $self->{'namespace'},
+            C4::Context->config('hostname'), C4::Context->config('database') );
+
+        $cache = Cache::FastMmap->new(
+            'share_file'  => $share_file,
+            'expire_time' => $self->{'timeout'},
+            'unlink_on_exit' => 0,
+        );
+    };
+    if ( $@ ) {
+        warn "FastMmap cache initialization failed: $@";
+        return;
+    }
+    return unless defined $cache;
+    $self->{'fastmmap_cache'} = $cache;
     return $self;
 }