Skip to content

Commit 76b45d2

Browse files
committed
fix: replace destructor with Proc::Simple's destroy flag in Database->add_listener
1 parent 130e773 commit 76b45d2

File tree

1 file changed

+5
-20
lines changed

1 file changed

+5
-20
lines changed

Anvil/Tools/Database.pm

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -177,26 +177,6 @@ sub parent
177177
return ($self->{HANDLE}{TOOLS});
178178
}
179179

180-
sub DESTROY
181-
{
182-
my $self = shift;
183-
184-
my $listeners = $self->{listeners};
185-
186-
# Clean up all lingering database listeners
187-
foreach my $forks (values %{$listeners})
188-
{
189-
foreach my $fork (values %{$forks})
190-
{
191-
next if not $fork->poll();
192-
193-
print "Database listener with PID: [".$fork->pid."] exiting on DESTROY.\n";
194-
195-
$fork->kill() or $fork->kill("SIGKILL");
196-
}
197-
}
198-
}
199-
200180

201181
#############################################################################################################
202182
# Public methods #
@@ -242,6 +222,11 @@ sub add_listener
242222

243223
my $listener = Proc::Simple->new();
244224

225+
# The reference of all listeners are stored in $self->{listeners}, which will be removed on DESTROY of $self.
226+
#
227+
# Set the flag to kill the listener when all references to it are removed.
228+
$listener->kill_on_destroy(1);
229+
245230
my $forked = $listener->start(\&run_listener, $self, $parameters);
246231

247232
if (not $forked)

0 commit comments

Comments
 (0)