Skip to content

Commit

Permalink
improve waiting after core reload (fixes #1361)
Browse files Browse the repository at this point in the history
  • Loading branch information
sni committed Jul 5, 2024
1 parent ff0598c commit 9718ae7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
35 changes: 24 additions & 11 deletions lib/Thruk/Authentication/User.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use strict;
use Carp qw/confess/;
use Cpanel::JSON::XS ();

use Thruk::Constants ':backend_handling';
use Thruk::Utils ();
use Thruk::Utils::Auth ();
use Thruk::Utils::Log qw/:all/;
Expand Down Expand Up @@ -104,8 +105,30 @@ sub set_dynamic_attributes {
return $self;
}

my $data;
my($data, $use_cached);
if($skip_db_access) {
$use_cached = 1;
} else {
_debug("fetching user data from livestatus") if Thruk::Base->verbose;
eval {
local $c->stash->{backend_errors_handling} = DIE;
my($alias, $email, $can_submit_commands, $groups,$src_peers) = $self->_fetch_user_data($c);
$data->{'alias'} = $alias if defined $alias;
$data->{'email'} = $email if defined $email;
$data->{'can_submit_commands'} = $can_submit_commands if defined $can_submit_commands;
$data->{'can_submit_commands_src'} = "set as contact attribute" if defined $can_submit_commands;
$data->{'contact_src_peer'} = $src_peers;
$data->{'contactgroups'} = $groups if defined $groups;
$data->{'timestamp'} = time();
};
my $err = $@;
if($err) {
_debug("failed to fetch user data from livestatus: %s", $err);
$use_cached = 1;
}
}

if($use_cached) {
_debug("using cached user data") if Thruk::Base->verbose;
my $cache = $c->cache->get->{'users'};
$data = {};
Expand All @@ -115,16 +138,6 @@ sub set_dynamic_attributes {
if($data->{'contactgroups'} && ref $data->{'contactgroups'} eq 'HASH') {
$data->{'contactgroups'} = [sort keys %{$data->{'contactgroups'}}];
}
} else {
_debug("fetching user data from livestatus") if Thruk::Base->verbose;
my($alias, $email, $can_submit_commands, $groups,$src_peers) = $self->_fetch_user_data($c);
$data->{'alias'} = $alias if defined $alias;
$data->{'email'} = $email if defined $email;
$data->{'can_submit_commands'} = $can_submit_commands if defined $can_submit_commands;
$data->{'can_submit_commands_src'} = "set as contact attribute" if defined $can_submit_commands;
$data->{'contact_src_peer'} = $src_peers;
$data->{'contactgroups'} = $groups if defined $groups;
$data->{'timestamp'} = time();
}

$self->_apply_user_data($c, $data);
Expand Down
2 changes: 2 additions & 0 deletions lib/Thruk/Utils.pm
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use Time::HiRes qw/gettimeofday tv_interval/;

use Thruk::Action::AddDefaults ();
use Thruk::Base qw/:compat/;
use Thruk::Constants ':backend_handling';
use Thruk::Utils::DateTime ();
use Thruk::Utils::Encode ();
use Thruk::Utils::Filter ();
Expand Down Expand Up @@ -2396,6 +2397,7 @@ sub wait_after_reload {
while($start > time() - $max_wait) {
$procinfo = {};
eval {
local $c->stash->{backend_errors_handling} = DIE;
local $SIG{ALRM} = sub { die "alarm\n" };
alarm(5);
$c->db->reset_failed_backends();
Expand Down

0 comments on commit 9718ae7

Please sign in to comment.