linux - Perl 中的 Rsync system() 执行随机失败并出现协议(protocol)错误

标签 linux perl rsync centos6 mod-perl

我们通常在 (Mod)Perl(和 PHP)中调用 rsync 并没有遇到太多问题,但是我们在运行一个在随后的请求顺利进行。有趣的是,即使我在代码中重试,对于同一个 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-path 参数后来被添加到那里用于调试。这是没有帮助的。无论哪种方式都失败了。

错误看起来像这样:

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 端点)几乎总是有效。

感谢任何帮助,因为这让我们发疯了......很长一段时间,尝试了许多修复。

最佳答案

如果这是一个真实的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/重试时记录/one_of_the_newest_logs

检查远程磁盘是否已满或目录是否存在?防火墙问题?远程和本地 rsync 或 ssh 版本(非常)不同? (虽然我想这应该会显示更清晰的错误信息)

关于linux - Perl 中的 Rsync system() 执行随机失败并出现协议(protocol)错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53663359/

相关文章:

mysql - 在mariadb中查询数据时如何包含两个SET语句

linux - 如何从ps中删除中间行?

perl - 如何将数组更改为哈希表?

perl - 如何将下一个搜索开始位置倒退1?

perl - 如何打包我的 Perl 脚本以在没有 Perl 的机器上运行?

linux - 用于监视新创建目录的 Bash 脚本

macos - rsync 在传输过程中突然无限期挂起

linux - 通过 Shell 脚本确定 Linux 进程是否正在使用给定参数运行

python - yum 安装 firefox 错误 - libnssutil3.so

linux - 强制 rsync 逐字节比较本地文件而不是校验和