UserAgent: memory leak
dpanech opened this issue · comments
Davlet Panech commented
- Mojolicious version: 9.31
- Perl version: v5.16.3
- Operating system: CentOS 7
Steps to reproduce the behavior
UserAgent leaks, here's a minimal example:
#!/usr/bin/perl
use warnings;
use strict;
use Mojo::IOLoop;
use Mojo::UserAgent;
# IOLoop
my $IOLOOP = Mojo::IOLoop->singleton;
# Create UA
my $UA = Mojo::UserAgent->new;
$UA->ioloop ($IOLOOP); # not sure if this is necessary
# Make a client request
my $COUNT = 0;
sub ua_test_1($$) {
my ($host, $port) = @_;
my $url = "http://$host:$port/";
++$COUNT;
$UA->get_p ($url)
->catch (sub {
print STDERR $host, ':', $port, ': ', @_, " [COUNT=$COUNT]\n"
})
->finally (sub {
$IOLOOP->next_tick (sub { ua_test_1 ($host, $port) });
--$COUNT;
});
}
ua_test_1 ("localhost", 1234); # some unused port for "connection refused"
print "PID=$$\n";
print "Press ENTER to start\n";
readline();
$IOLOOP->start();
Expected behavior
Memory usage should remain steady while this script is running.
Actual behavior
Memory reported by top (the VIRT
column) steadily increases by approx 20 KiB per second.
Note that the example above doesn't involve self-referencing closures - AFAICT - so it can't be that.
Sebastian Riedel commented
Not a leak, you're just not giving the event loop any time to do actual work.