简体   繁体   English

使用 HTTPS 的 Perl LWP 内存泄漏

[英]Memory leak with Perl's LWP using HTTPS

I think I found a memory leak with LWP when connecting via HTTPS.我想我在通过 HTTPS 连接时发现了 LWP 的内存泄漏。 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 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 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.通过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.经过一些测试,我发现,随着最近我的库的升级,仍然存在内存泄漏,但只有当您通过 HTTPS调用某些地址时才会发生这种情况 In the above example I was calling https://www.google.com , and it happens to be one of those addresses.在上面的例子中,我打电话给https://www.google.com ,它恰好是这些地址之一。 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我报告了这个错误,其他一些人也证实了我的发现: https : //rt.cpan.org/Ticket/Display.html?id=88287

On linux, with perl 5.10, Crypt 0.58, Lwp 6.02 the memory usage is constant.在 linux 上,使用 perl 5.10、Crypt 0.58、Lwp 6.02,内存使用量是恒定的。 try to upgrade your perl modules to the latest one.尝试将您的 perl 模块升级到最新版本。

If the issue is still present, create an RT ticket for this issue and the maintaner of this module will fix the leak.如果问题仍然存在,请为此问题创建 RT 票证,此模块的维护人员将修复泄漏。

Regards,问候,

It appears, at least for me, that you can work around this problem by disabling verify hostname:至少对我而言,您似乎可以通过禁用验证主机名来解决此问题:

my $ua = LWP::UserAgent->new(ssl_opts => { verify_hostname => 0 });

Obviously this is not recommended if security is important to your application!显然,如果安全性对您的应用程序很重要,则不建议这样做!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM