diff --git a/bin/pt-agent b/bin/pt-agent index 8a1c4d60..ece2fc54 100755 --- a/bin/pt-agent +++ b/bin/pt-agent @@ -4975,13 +4975,20 @@ sub _log { return; } -sub DESTROY { +sub stop_online_logging { my $self = shift; - if ( $self->online_logging ) { + if ( $self->_thread && $self->_thread->is_running() ) { my @stop :shared = (undef, undef); $self->_message_queue->enqueue(\@stop); # stop the thread $self->_thread->join(); } + $self->online_logging(0); + return; +} + +sub DESTROY { + my $self = shift; + $self->stop_online_logging(); return; } @@ -5365,8 +5372,8 @@ sub main { $logger->info("pt-agent exit $exit_status, oktorun $oktorun"); - # Cause Logger::DESTORY to be called. - $logger = undef; + $logger->stop_online_logging(); + $logger->info('Waiting for logging thread to stop...'); return $exit_status; } diff --git a/lib/Percona/Agent/Logger.pm b/lib/Percona/Agent/Logger.pm index 2b59ebc7..b291abef 100644 --- a/lib/Percona/Agent/Logger.pm +++ b/lib/Percona/Agent/Logger.pm @@ -207,13 +207,20 @@ sub _log { return; } -sub DESTROY { +sub stop_online_logging { my $self = shift; - if ( $self->online_logging ) { + if ( $self->_thread && $self->_thread->is_running() ) { my @stop :shared = (undef, undef); $self->_message_queue->enqueue(\@stop); # stop the thread $self->_thread->join(); } + $self->online_logging(0); + return; +} + +sub DESTROY { + my $self = shift; + $self->stop_online_logging(); return; }