记一个gitea推送失败的问题

我的博客的推送一份是在github
作为github page,另一份是在自建的gitea上面
上周突然就出现推送失败了
在gpt5.5老师的指导下一顿查gitea服务器的日志也没查出来原因
一开始说是可以尝试从https切换到ssh形式也没起作用
服务端日志也没有用的
然后这次升级了gpt5.6老师以后,就再问了下

1
2
3
4
send-pack: unexpected disconnect while reading sideband packet
Writing objects: 100% (6455/6455), 2.95 MiB | 1.53 MiB/s, done.
Total 6455 (delta 2752), reused 6281 (delta 2580), pack-reused 0
fatal: the remote end hung up unexpectedly

这次的日志比较有价值可能
另外还有个信息是之前git gc因为仓库的小文件太多了可能
然后这次gpt老师给出的方法是

1
2
http.postBuffer = 16777216
http.version = HTTP/1.1

把postBuffer给调大了,然后直接在仓库里执行

1
git -C .deploy_git push --verbose

发现直接可以了
具体原因分析下来是: 推送产生的请求体约为 2.95 MiB,超过了 Git 默认 1 MiB 的 http.postBuffer。

1
2
3
4
5
6
7
8
9
10
11
推送数据 2.95 MiB
↓ 超过默认缓冲区 1 MiB
Git 改用 chunked 分块传输

Traefik / Gitea 链路没有正确处理该请求

返回 HTTP 200,但响应体为 0

Git 收不到 receive-pack 的 sideband 结果

unexpected disconnect

因为默认的postBuffer不够大,然后使用了chunked传输,是指一块块传,直到最后一块大小为0
然后因为我的gitea可能经过了traefik和gitea中间有不支持的
关于postBuffer在git官方文档也有解释

http.postBuffer

1
2
3
Maximum size in bytes of the buffer used by smart HTTP transports when POSTing data to the remote system. For requests larger than this buffer size, HTTP/1.1 and Transfer-Encoding: chunked is used to avoid creating a massive pack file locally. Default is 1 MiB, which is sufficient for most requests.

Note that raising this limit is only effective for disabling chunked transfer encoding and therefore should be used only where the remote server or a proxy only supports HTTP/1.0 or is noncompliant with the HTTP standard. Raising this is not, in general, an effective solution for most push problems, but can increase memory consumption significantly since the entire buffer is allocated even for small pushes.

翻译下

1
2
3
4
5
Git 使用智能 HTTP 传输协议向远程服务器发送 POST 请求时,所使用缓冲区的最大大小,单位为字节。
当请求大小超过这个缓冲区时,Git 会使用 HTTP/1.1 的 Transfer-Encoding: chunked,也就是分块传输编码,以避免在本地创建一个非常大的 pack 文件。
默认值是 1 MiB,对于大多数请求来说已经足够。
需要注意的是,增大这个值的作用仅仅是停用分块传输编码。因此,只有在远程服务器或中间代理仅支持 HTTP/1.0,或者没有正确遵循 HTTP 标准时,才应该提高这个限制。
一般来说,增大这个值并不能解决大多数 Git 推送问题。同时它还可能显著增加内存占用,因为即使实际推送的数据很小,Git 也会分配完整大小的缓冲区。

对于我这样的hexo是在.deploy_git目录里的.git/config文件
普通git仓库如果要配置就是在.git/config里进行配置

1
2
3
[http]
postBuffer = 16777216
version = HTTP/1.1

可以直接改这个文件,也可以用git配置命令

1
2
git config http.postBuffer 16777216
git config http.version HTTP/1.1

这样都可以,在现在这个时代
发现这样一个小技巧或者小问题的答案
我还是想记录下
因为很多的东西感觉已经被GPT这样的颠覆掉了
有这些小的问题被解决
感觉有种久违的愉悦感
排查问题,找到原因是个很有意思的过程
并把它解决也是很有意思
这个可能就算是初心了吧
就能把解决问题的思路方法分享下
也是一种比较开始的事情