在Perl的rsync系统()执行与协议错误随机失败

问题描述 投票:1回答:2

我们通常所说的rsync中(MOD)的Perl(和PHP),并没有遇到太多的问题,但我们正在运行一个命令时,当在后续请求运行经过精细运行到偶尔协议错误。有趣的是,即使我在代码重试,对于相同的HTTP请求时,它会失败每一次,但如果你再拍http请求它可能会成功。

代码如下所示:

$cmd = sprintf('rsync -auvvv --rsync-path="rsync --log-file=/tmp/ui-rsync.log" %s %s', "$fromDir/$fromBase/", "$path/$toBase/");
$exitCode = system($cmd);

在加入该--rsync路径参数有更高版本的调试。这是无益的。它失败无论哪种方式。

这些错误是这样的:

rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: error in rsync protocol data stream (code 12) at io.c(600) [sender=3.0.6]

或者是这样的:

unexpected tag 93 [receiver]
rsync error: error in rsync protocol data stream (code 12) at io.c(1134) [receiver=3.0.6]
rsync: connection unexpectedly closed (9 bytes received so far) [sender]
rsync error: error in rsync protocol data stream (code 12) at io.c(600) [sender=3.0.6]

我调试的实际生成的命令,我可以通过手细运行它们。

在HTTP用户可以运行的命令的罚款。

同样,一个纲领性的重试从不工作,但手动重试(命中触发它的同一HTTP端点),作品几乎总是如此。

感谢所有帮助,因为这已经驱使我们疯了......很长一段时间,有许多修复尝试。

linux perl rsync centos6 mod-perl
2个回答
1
投票

如果这是一个真正的heisenbug,你可以重试rsync的与之间的一些睡眠也许三次:

for my $n (1..3){
   my $exitCode = system($cmd);
   my_log_sub("SUCCESS: rsync succeded on try $n") + last if $exitCode==0;
   my_log_sub("ERROR: rsync $n of 3 failed: $cmd $! $?");
   sleep(1) if $n<3;
}

你检查你的本地和远程日志?尝试sudo ls -rtl /var/log/sudo ls -rtl /var/log/httpd/后立即失效,虽然重试tail -f /var/log/one_of_the_newest_logs

你检查,如果远程磁盘已满,或者如果该目录存在?防火墙的问题?远程和本地的rsync或ssh版本(很)有什么不同? (虽然我想这应该表现出更清晰的错误消息)


0
投票

解决的办法是改变系统()来反引号。认真。我不知道为什么它的工作原理。

这种变化从字面上是这样的:

# BAD:
$exitCode = system($cmd);
# GOOD:
`$cmd`;

如果我猜我会说有一个与外壳是如何被初始化的一些细微的差别,也许一些环境变量或内存位置不正确的清洁。我真的不知道,但。

© www.soinside.com 2019 - 2024. All rights reserved.