Search code examples
perlmemory-leakslwp

Memory leak with Perl's LWP using HTTPS


I think I found a memory leak with LWP when connecting via HTTPS. With the following script, memory usage increases constantly:

use LWP::UserAgent;

$ua = LWP::UserAgent->new();
$request = HTTP::Request->new(GET=>'https://www.google.com/');
while (1) {
  $response = $ua->request($request);
  sleep(1);
}

This other script has no problems:

use LWP::UserAgent;

$ua = LWP::UserAgent->new();
$request = HTTP::Request->new(GET=>'http://www.google.com/'); # https => http
while (1) {
  $response = $ua->request($request);
  sleep(1);
}

Perl 5.12.3 / LWP 5.837 / Crypt::SSLeay 0.58 / Mac OS X 10.7.4

Does anyone know a way around this?


UPDATE

Perl 5.12.4 / LWP 6.05 / Crypt::SSLeay 0.64 / Mac OS X 10.8.4

The memory leak still exists when connecting through HTTPS. To try it out, run the sample script on the terminal, and see the memory grow and grow with the Activity Monitor.


UPDATE

After some testing I found out that, with the recent upgrade of my libraries, there is still a memory leak, but it only happens when you call certain addresses over HTTPS. In the above example I was calling https://www.google.com, and it happens to be one of those addresses. For instance, this code gives me no memory leaks:

use LWP::UserAgent;

$ua = LWP::UserAgent->new();
$request = HTTP::Request->new(GET=>'https://twitter.com/'); # www.google.com => twitter.com
while (1) {
  $response = $ua->request($request);
  sleep(1);
}


UPDATE

I reported the bug and some other people have confirmed my findings: https://rt.cpan.org/Ticket/Display.html?id=88287


Solution

  • On linux, with perl 5.10, Crypt 0.58, Lwp 6.02 the memory usage is constant. try to upgrade your perl modules to the latest one.

    If the issue is still present, create an RT ticket for this issue and the maintaner of this module will fix the leak.

    Regards,