Skip Menu |

This queue is for tickets about the AnyEvent-Process CPAN distribution.

Report information
The Basics
Id: 101915
Status: resolved
Worked: 2 hours (120 min)
Priority: 0/
Queue: AnyEvent-Process

People
Owner: PETRIS [...] cpan.org
Requestors: bob.kleemann [...] tealium.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: 0.02



Subject: Memory Leak
Date: Tue, 3 Feb 2015 16:47:04 -0800
To: bug-AnyEvent-Process [...] rt.cpan.org
From: Bob Kleemann <bob.kleemann [...] tealium.com>
It appears that AnyEvent::Process has a memory leak. While running the following, I get a definite increase in the size of memory (about 7-8 MB) used by Perl: #! /usr/bin/env perl use v5.18; use AnyEvent; use AnyEvent::Process; use Errno qw(:POSIX); use Devel::SizeMe qw(perl_size); say perl_size; for ( 1 .. 1_000_000 ) { my $arg = rand; my ( $stdout, $stderr ) = ( '', '' ); my $cv = AnyEvent->condvar; my $run = AnyEvent::Process->new()->run( args => [ $arg ], code => sub { exec 'echo', @_ }, kill_interval => 10, on_completion => sub { my ( $job, $exit ) = @_; $cv->send($exit); }, on_kill => sub { my $job = shift; $job->kill(9); $cv->send(-1); }, fh_table => [ #\*STDIN => [ qw( open < /dev/null ) ], \*STDOUT => [ qw( pipe > handle ), [ on_eof => sub { }, # Ignore EOF on_read => sub { $stdout = $_[0]->rbuf }, on_error => sub { return if $! == EPIPE; }, ] ], \*STDERR => [ qw( pipe > handle ), [ on_eof => sub { }, # Ignore EOF on_read => sub { $stderr = $_[0]->rbuf }, on_error => sub { return if $! == EPIPE; }, ] ], ], ); my $return = $cv->recv; die $return if $return; $run->close; undef $run; #undef $cv; say perl_size unless $_ % 1_000; } say perl_size;
Subject: Re: [rt.cpan.org #101915] AutoReply: Memory Leak
Date: Wed, 4 Feb 2015 14:57:59 -0800
To: bug-AnyEvent-Process [...] rt.cpan.org
From: Bob Kleemann <bob.kleemann [...] tealium.com>
I've figured out the issue, AnyEvent::Process::Job creates a circular reference with it's callbacks. Updating the close method to clear out the timers and callbacks in addition to the handles causes the memory to be returned. I've attached a patch.

Message body is not shown because sender requested not to inline it.

Hi! I've resolved the leak by clearing callbacks explicitly in the last callback executed. Thanks for reporting it.