From 94175e21e2271b78ab5693eed528ebe6f486365b Mon Sep 17 00:00:00 2001 From: Damyan Ivanov Date: Thu, 25 Nov 2021 20:58:17 +0000 Subject: [PATCH] keep $loop variable at closure reach otherwise it can't be stopped from within the closure, and $mpd->loop may be the thing from re-init-ed $mpd (after a reconnect) --- lib/App/MPD/Feeder.pm | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/App/MPD/Feeder.pm b/lib/App/MPD/Feeder.pm index c951c70..8561cf8 100644 --- a/lib/App/MPD/Feeder.pm +++ b/lib/App/MPD/Feeder.pm @@ -91,6 +91,8 @@ method init_mpd { } ); + my $loop = $mpd->loop; + my $int_signal_handler = sub { state $signal_count = 0; $signal_count++; @@ -103,12 +105,12 @@ method init_mpd { $log->debug("Signal received. Stopping loop"); $quit_requested = 1; - $mpd->loop->stop('quit'); + $loop->stop('quit'); $self->break_idle; }; for (qw(TERM INT)) { - $mpd->loop->add( + $loop->add( IO::Async::Signal->new( name => $_, on_receipt => $int_signal_handler, @@ -116,19 +118,19 @@ method init_mpd { ); } - $mpd->loop->add( + $loop->add( IO::Async::Signal->new( name => 'HUP', on_receipt => sub { $log->debug("SIGHUP received. Scheduling reload"); $reload_requested = 1; - $mpd->loop->stop('reload'); + $loop->stop('reload'); $self->break_idle; }, ) ); - $mpd->loop->add( + $loop->add( IO::Async::Signal->new( name => 'USR1', on_receipt => sub { @@ -371,12 +373,15 @@ method run_loop { $self->init_mpd; - $mpd->loop->add( + my $loop = $mpd->loop; + + $loop->add( IO::Async::Timer::Periodic->new( interval => 60, on_tick => sub { if (!$mpd_connected) { $log->trace("Not connected to MPD. Skipping alive check."); + $loop->stop('disconnected'); return; } -- 2.39.5