From b4871538007900de849a0917043c035afd936d0f Mon Sep 17 00:00:00 2001 From: Ramon Novoa Date: Fri, 10 Jul 2020 13:21:30 +0200 Subject: [PATCH] Lock on LIFO mode if the agent does not exist to prevent duplicates. Ref pandora_enterprise#5908 --- pandora_server/lib/PandoraFMS/DataServer.pm | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/pandora_server/lib/PandoraFMS/DataServer.pm b/pandora_server/lib/PandoraFMS/DataServer.pm index 69efd9f45a..ef2e975b13 100644 --- a/pandora_server/lib/PandoraFMS/DataServer.pm +++ b/pandora_server/lib/PandoraFMS/DataServer.pm @@ -117,7 +117,7 @@ sub run ($) { ############################################################################### sub data_producer ($) { my $self = shift; - my $pa_config = $self->getConfig (); + my ($pa_config, $dbh) = ($self->getConfig (), $self->getDBH ()); my @tasks; my @files; @@ -162,7 +162,7 @@ sub data_producer ($) { next if ($file !~ /^(.*)[\._]\d+\.data$/); my $agent_name = $1; - next if (agent_lock($pa_config, $agent_name) == 0); + next if (agent_lock($pa_config, $dbh, $agent_name) == 0); push (@tasks, $file); } @@ -1064,9 +1064,16 @@ sub process_xml_matrix_network { # Get a lock on the given agent. Return 1 on success, 0 otherwise. ########################################################################## sub agent_lock { - my ($pa_config, $agent_name) = @_; + my ($pa_config, $dbh, $agent_name) = @_; - return 1 if ($pa_config->{'dataserver_lifo'} == 1); + # Do not lock on LIFO mode if the agent already exist. + # get_agent_id will be called again from process_xml_data, + # so the should be no race conditions if the agent does + # not exist. + if ($pa_config->{'dataserver_lifo'} == 1 && + get_agent_id ($dbh, $agent_name) > 0) { + return 1; + } $AgentSem->down (); if (defined ($Agents{$agent_name})) {