【发布时间】:2012-06-27 00:52:06
【问题描述】:
更新
根据理论,我编辑了LWP/Protocol/http.pm,在子例程request 中包含一个睡眠语句:
if (!$has_content || $write_wait || $has_content > 8*1024) {
WRITE:
{
# Since this just writes out the header block it should almost
# always succeed to send the whole buffer in a single write call.
my $n = $socket->syswrite($req_buf, length($req_buf));
sleep 2; ## <----- NEW
unless (defined $n) {
...
get 语句有效,返回了200 OK。非常感谢 Alan Curry 帮助调试和在代码中找到这个特定位置。
不确定它是否完全回答了问题,或者该解决方案是否长期有效。将不得不进行更多检查。
总结:
-
LWP::UserAgent 模块使用
get子例程对于某些 URL 失败,报告 500 超时。 - 只有 一些 URL 失败。例如。
www.google.com失败,但www.google.se成功。 - 我没有其他连接问题,所有 URL 都可以通过浏览器和 ping 等 cmd 程序访问。
- 由于这个问题,我无法使用 CPAN 或 ActivePerl 的 ppm 安装 perl 模块。
- 安装另一个 perl 发行版后问题仍然存在。
- 奇怪的是,使用调试器并单步执行代码会使失败的 URL 成功。
- 我正在使用防火墙,并且允许 perl 建立连接。 (不相关,因为某些 URL 成功)
- 防火墙日志显示允许 perl 连接失败的 URL 和非失败的 URL。 (见下文)日志还显示套接字打开以进行侦听,但时间戳与失败的连接不匹配。
目标
- 我主要是在寻找能够安装模块的任何解决方案。
- 我对有关如何调试问题的所有建议感兴趣,不需要完整的解决方案。欢迎任何提示或提示。
细化
我使用 ActivePerl v5.14 已经有一段时间了。使用 Perl 包管理器 ppm 命令和 gui 安装模块效果很好,但在某些时候停止工作,报告 500 超时。 cpan shell 报告了同样的情况。
我在谷歌上广泛搜索了这个问题,但没有发现任何与我的问题相关的内容,也没有任何帮助。
ActivePerl 支持声称它可能是一个代理设置,这很可笑。我有很多不需要代理设置的连接到互联网的程序,据我所知,我不需要这样做。我试图找出我的代理设置是什么(如果有的话),但我发现的唯一内容是模糊的引用,例如“使用系统设置”、“不需要代理”和“代理与您的 IP 相同”。
所以昨晚我受够了并安装了草莓 perl,但它遇到了同样的问题。之后我卸载了 ActivePerl。
无论如何,我已经用 LWP 模块进行了实验,发现我可以在那里重现错误。它似乎仅限于某些网站,而 cpan 就是其中之一(?)。我创建了这个脚本用于测试:
use strict;
use warnings;
use LWP::UserAgent;
use URI;
my $ua = LWP::UserAgent->new;
my $url = shift;
my $u = URI->new($url);
$ua->no_proxy('cpan.strawberryperl.com','cpan.com',$u->host);
$ua->timeout(30);
my $r = $ua->get($url);
if ($r->is_success) {
print $r->decoded_content;
} else {
die $r->status_line;
}
然后做了一些测试:
tx.pl http://cpan.strawberryperl.com/authors/01mailrc.txt.gz
500 read timeout at tx.pl line 23.
tx.pl http://stackoverflow.com
500 read timeout at tx.pl line 23.
tx.pl http://www.google.se
<!doctype html><html itemscope itemtype="http://schema.org/WebPage"><head><meta
http-equiv="content-type" content="text/html; charset=ISO-8859-1"><meta ...
所以,google 有效,www.youtube.com 也有效,但 www.yahoo.com 和 search.cpan.com 失败。 180 秒的默认超时使调试变得非常烦人,这就是我在脚本中减少它的原因。不用说,如果我尝试使用 Firefox 或 ping 访问这些 URL,所有这些 URL 都可以访问。
预计到达时间:
奇怪的是,通过调试器运行脚本,打开跟踪并跳到最后,使之前失败的连接成功。
这似乎意味着当脚本由于打印数千行跟踪代码而运行得更慢时,存在某种“固定”的打嗝、错过的计时。
我可以将这个问题理解为一些 ActivePerl 模块损坏的结果,但草莓 perl 使用的是完全不同的文件集,所以它一定是我的系统。
为什么有些网站有效而有些无效,这令人费解。我可以理解一些像 stackoverflow.com 这样的网站会保护自己免受潜在的机器人攻击,但是为什么 cpan 会阻止它自己的包管理器是没有意义的。
我正在使用防火墙,并且允许 Perl 建立连接。我的系统是相当旧的 Windows XP 安装(约 5 年)。在使用 Ubuntu 运行双启动时,我从未遇到过这个问题,这是另一个与代理无关的线索。
我很好,真的很难过。如果有人能帮我调试一下,我将不胜感激。
下面的 CPAN shell 错误消息。有趣的是,它说它试图使用 ftp 作为最后的手段,但我刚刚发现我的防火墙不允许使用 ftp 命令,如果使用它,它应该请求我的许可。
Fetching with LWP:
http://cpan.strawberryperl.com/authors/01mailrc.txt.gz
LWP failed with code[500] message[read timeout]
Warning: no success downloading 'D:\strawberry\cpan\sources\authors\01mailrc.txt
.gz.tmp1252'. Giving up on it.
Fetching with LWP:
http://www.cpan.org/authors/01mailrc.txt.gz
LWP failed with code[500] message[read timeout]
Warning: no success downloading 'D:\strawberry\cpan\sources\authors\01mailrc.txt
.gz.tmp1252'. Giving up on it.
Warning: no success downloading 'D:\strawberry\cpan\sources\authors\01mailrc.txt
.gz.tmp1252'. Giving up on it.
As a last resort we now switch to the external ftp command 'C:\WINDOWS\system32\
ftp.EXE'
to get 'D:\strawberry\cpan\sources\authors\01mailrc.txt.gz.tmp1252'.
Doing so often leads to problems that are hard to diagnose.
If you're the victim of such problems, please consider unsetting the
ftp config variable with
o conf ftp ""
o conf commit
Please check, if the URLs I found in your configuration file
(http://cpan.strawberryperl.com/, http://www.cpan.org/) are valid. The
urllist can be edited. E.g. with 'o conf urllist push ftp://myurl/'
Could not fetch authors/01mailrc.txt.gz
尝试获取非失败 URL (www.google.se) 和失败 (stackoverflow.com) 的防火墙日志:
2012-06-27T18:34:04+01:00,info,appl control,C:\WINDOWS\system32\svchost.exe,allow,listen,17,0.0.0.0,56564
2012-06-27T18:34:04+01:00,info,appl control,C:\WINDOWS\system32\svchost.exe,allow,send,17,195.54.122.198,53
2012-06-27T18:34:13+01:00,info,appl control,D:\strawberry\perl\bin\perl.exe,allow,connect out,6,64.34.119.12,80
2012-06-27T18:34:13+01:00,info,appl control,D:\strawberry\perl\bin\perl.exe,allow,connect out,6,64.34.119.12,80
2012-06-27T18:34:21+01:00,info,appl control,C:\Program\Mozilla Firefox\firefox.exe,allow,connect out,6,74.86.70.106,80
2012-06-27T18:34:28+01:00,info,appl control,C:\Program\Mozilla Firefox\firefox.exe,allow,connect out,6,64.34.119.12,80
2012-06-27T18:34:30+01:00,info,appl control,C:\WINDOWS\system32\svchost.exe,allow,listen,17,0.0.0.0,56664
2012-06-27T18:34:30+01:00,info,appl control,C:\WINDOWS\system32\svchost.exe,allow,send,17,195.54.122.198,53
2012-06-27T18:34:30+01:00,info,appl control,D:\strawberry\perl\bin\perl.exe,allow,connect out,6,74.125.143.94,80
2012-06-27T18:34:30+01:00,info,appl control,D:\strawberry\perl\bin\perl.exe,allow,connect out,6,74.125.143.94,80
2012-06-27T18:35:14+01:00,info,appl control,C:\Program\Mozilla Firefox\firefox.exe,allow,connect out,6,64.34.119.12,80
2012-06-27T18:35:21+01:00,info,appl control,C:\Program\Mozilla Firefox\firefox.exe,allow,connect out,6,74.86.70.106,80
2012-06-27T18:36:21+01:00,info,appl control,C:\Program\Mozilla Firefox\firefox.exe,allow,connect out,6,74.86.70.106,80
2012-06-27T18:37:04+01:00,info,appl control,C:\WINDOWS\system32\svchost.exe,allow,listen,17,0.0.0.0,61215
2012-06-27T18:37:04+01:00,info,appl control,C:\WINDOWS\system32\svchost.exe,allow,send,17,195.54.122.198,53
2012-06-27T18:37:07+01:00,info,appl control,D:\strawberry\perl\bin\perl.exe,allow,connect out,6,64.34.119.12,80
2012-06-27T18:37:07+01:00,info,appl control,D:\strawberry\perl\bin\perl.exe,allow,connect out,6,64.34.119.12,80
【问题讨论】:
-
如果你找到 LWP 包并重命名它一段时间,CPAN 会怎么做,所以它会变得不可用?是否会重新安装 LWP?
-
既然您提到它可以在同一网络上与 Ubuntu 一起正常工作,这可能与您的 Windows 安装有关。您是否尝试过关闭 Windows 防火墙并查看是否有影响?您还可以查看
Net::Config或.libnetrc,其中包含各种 Perl 网络模块的配置选项。使用perldoc -l Net::Config查找它。 -
@Schwern 关闭防火墙并没有改变任何东西。恐怕我对这些配置选项一无所知,它仍然无法解释为什么有些网站可以联系而有些则不能。
-
这种Heisenbugs 几乎不可能远程诊断。去找一位专家,让他/她坐在你的电脑前。