You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Gitea仓库Git克隆失败,提示transfer closed with outstanding read data remaining

Git稀疏浅克隆失败(curl 18/early EOF)的排查与解决

问题背景

服务器运行Gitea 1.20.6,客户端执行稀疏浅克隆命令:

GIT_CURL_VERBOSE=1 GIT_TRACE=1  git clone --sparse --depth 1 https://myuser:mypwd@myserver/git/mydir/myrepo.git 

克隆失败,客户端日志报错:

error: RPC failed; curl 18 transfer closed with outstanding read data remaining
error: 2 bytes of body are still expected
remote: Compressing objects:  63% (27428/4353500
fetch-pack: unexpected disconnect while reading sideband packet
fatal: early EOF
fatal: fetch-pack: invalid index-pack output

服务器日志显示请求最终返回200 OK,但耗时长达133秒,已尝试设置http.postbuffer、core.compression=0等全局Git配置,问题未解决。

解决方案

1. 调整Gitea及反向代理的超时配置

服务器端请求耗时远超常规阈值,大概率是超时设置过短导致连接被提前断开:

  • 修改Gitea的app.ini配置文件,延长HTTP超时:
    [server]
    HTTP_TIMEOUT = 300  # 设置为300秒(5分钟),可根据实际情况调整
    
  • 若使用Nginx等反向代理,同步调整代理超时参数:
    location / {
        proxy_connect_timeout 300s;
        proxy_send_timeout 300s;
        proxy_read_timeout 300s;
        # 其他代理配置...
    }
    
  • 重启Gitea及反向代理服务生效。

2. 优化克隆命令参数

针对稀疏浅克隆的场景,添加额外参数规避传输中断:

  • 直接在克隆命令中关闭压缩,减少服务器端压缩耗时和传输体积:
    GIT_CURL_VERBOSE=1 GIT_TRACE=1 git clone --sparse --depth 1 --no-compression https://myuser:mypwd@myserver/git/mydir/myrepo.git
    
  • 拆分操作:先完成浅克隆,再配置稀疏检出:
    git clone --depth 1 https://myuser:mypwd@myserver/git/mydir/myrepo.git
    cd myrepo
    git sparse-checkout init --cone
    git sparse-checkout add <目标目录路径>
    

3. 配置服务器端Git的upload-pack参数

Gitea依赖Git的upload-pack服务,调整其超时和权限配置:
在服务器端执行:

git config --global uploadpack.timeout 300
git config --global uploadpack.allowReachableSHA1InWant true

前者延长upload-pack的超时时间,后者确保浅克隆的SHA1请求被允许处理。

4. 切换克隆协议或排查网络限制

  • 尝试使用SSH协议克隆,绕过HTTPS层面的传输限制:
    git clone --sparse --depth 1 git@myserver:mydir/myrepo.git
    
  • 检查客户端与服务器之间的防火墙、路由器是否存在连接超时规则,部分设备会主动断开长时间低速传输的连接,需调整对应规则。

5. 调整客户端Git的低速连接判断配置

关闭客户端对低速连接的自动中断机制:

git config --global http.lowSpeedLimit 0
git config --global http.lowSpeedTime 900

这会让Git忽略传输速度,避免因数据传输缓慢被客户端主动终止连接。

内容的提问来源于stack exchange,提问作者MMM

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.29 21:45:31