GitHub Actions部署Magento应用时首次运行偶发curl error 55错误(重试可恢复)求助
GitHub Actions部署Magento应用时首次运行偶发curl error 55错误(重试可恢复)求助
大家好,我被一个问题困扰快半年了:用GitHub Actions部署Magento应用时,首次执行部署工作流总会抛出curl error 55的错误,但重新运行失败的任务后又能顺利完成。
错误日志如下:
https://repo.packagist.org could not be fully loaded (curl error 55 while downloading https://repo.packagist.org/p2/magento/language-pt_br~dev.json: Failed sending data to the peer), package information was loaded from the local cache and may be out of date
我的部署运行环境是CentOS 7,curl版本信息:
curl 7.61.1 (x86_64-redhat-linux-gnu) libcurl/7.61.1 OpenSSL/1.1.1c zlib/1.2.11 brotli/1.0.6 libidn2/2.2.0 libpsl/0.20.2 (+libidn2/2.0.5) libssh/0.9.0/openssl/zlib nghttp2/1.41.0 Release-Date: 2018-09-05 Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp scp sftp smb smbs smtp smtps telnet tftp Features: AsynchDNS IDN IPv6 Largefile GSS-API Kerberos SPNEGO NTLM NTLM_WB SSL libz brotli TLS-SRP HTTP2 UnixSockets HTTPS-proxy PSL Metalink
我自己梳理的可能原因
- 网络连接不稳定:curl error 55本质是发送数据到对等方时失败,大概率是首次运行时GitHub Actions runner和Packagist之间的网络出现了临时波动,比如TCP连接意外中断、数据包丢失。
- 缓存加载的时序问题:首次运行时本地没有有效缓存,需要从Packagist拉取完整的包信息,这个过程网络压力大,容易触发发送失败;重试时可能已经缓存了部分数据,或者网络连接恢复,所以能成功。
- 旧版curl的兼容性bug:当前用的curl是2018年的7.61.1版本,比较老旧,可能在HTTP/2协议交互、TLS握手的稳定性上存在已知问题,和Packagist服务器通信时偶尔出状况。
我尝试过的解决方案思路,还想听听大家的建议
给Composer命令加重试逻辑
在GitHub Actions的部署步骤里,给依赖安装命令套个循环重试的逻辑,避免单次失败就终止任务:- name: Install Magento dependencies run: | retries=3 count=0 until [ $count -ge $retries ] do composer install --no-interaction --prefer-dist && break count=$((count+1)) echo "Retry $count/$retries..." sleep 5 done升级curl版本
在CentOS 7环境下通过EPEL源升级curl到较新的稳定版本,修复旧版本的已知bug:# 安装EPEL源 sudo yum install epel-release -y # 升级curl sudo yum update curl -y # 验证版本 curl --version强制Composer使用HTTP/1.1
有些旧版curl在HTTP/2下稳定性较差,强制切换到HTTP/1.1试试:composer config repo.packagist.org composer https://repo.packagist.org --global composer config --global http-protocol http/1.1延长Composer的超时时间
给网络请求多留一些时间完成数据发送:composer install --no-interaction --prefer-dist --timeout=120
有没有遇到过类似问题的朋友?或者有其他更有效的解决方案,欢迎分享!
备注:内容来源于stack exchange,提问作者Rajsekar Reddy




