LoginSignup
3
2

unexpected disconnect while reading sideband packet

Last updated at Posted at 2024-03-14

事象 : RPC failed; curl 18 transfer closed with outstanding read data remaining

  • 環境
    • Windows 11 Pro
    • git version 2.42.0.windows.2
# Gitのリポジトリをクローンしたらエラーになった。
$ git clone https://github.com/user/repo-name.git
Cloning into 'repo-name'...
remote: Enumerating objects: 58103, done.
remote: Counting objects: 100% (3115/3115), done.
remote: Compressing objects: 100% (970/970), done.
error: RPC failed; curl 18 transfer closed with outstanding read data remaining
error: 2413 bytes of body are still expected
fetch-pack: unexpected disconnect while reading sideband packet
fatal: early EOF
fatal: fetch-pack: invalid index-pack output

原因 : リポジトリのサイズが大きすぎる

今回は、以下の対策を講じましたが、完全に解決することはできませんでした。
ただ、いろんな記事を見ていると以下のどれかで解決することもあるようです。

  1. バッファ最大サイズを大きくする
    • やり取りするサイズを大きくして何とかするという策でしたが、何回かやるとうまくいったりエラーになったりと安定しませんでした。
  2. 最新の履歴だけ取得する
    • 大きすぎるので取得する履歴を限定するという策です。

対応1 : バッファ最大サイズを大きくする

http.postBuffer
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.
Git - git-config Documentation

Gitのドキュメントを一生懸命和訳してみると、
HTTPで使用するバッファ最大サイズがGitの設定にあり、バッファ最大サイズよりも大きいリクエストでは「HTTP/1.1」と「Transfer-Encoding:chunked(データをチャンクという塊に区切る)」を使用することで大規模なファイルをローカルへ作成しないようにしているそうです。
バッファ最大サイズのデフォルトは「1MiB」になっています。

参考 : Transfer-Encodingとは - 意味をわかりやすく - IT用語辞典 e-Words

Gitのドキュメントにはサイズを上げる注意が記載されており、無駄に大きくしないように試しながらサイズを決めたほうがよさそうです。

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.
Git - git-config Documentation

# 確認してみると「http.postBuffer」は未設定であるため、デフォルトの「1MiB」になっている
$ git config --global http.postBuffer
# サイズは「byte」で設定するので、以下で「500MB」です(1024Bx1024KBx500MB)
$ git config --global http.postBuffer 524288000
$ cat ~/.gitconfig | grep -e http -e postBuffer
[http]
        postBuffer = 524288000
# 何回かやると「うまくいったり」「エラーになったり」・・・
$ git clone https://github.com/user/repo-name.git
Cloning into 'repo-name'...
remote: Enumerating objects: 58103, done.
remote: Counting objects: 100% (3115/3115), done.
remote: Compressing objects: 100% (970/970), done.
error: RPC failed; curl 18 transfer closed with outstanding read data remaining
error: 5734 bytes of body are still expected
fetch-pack: unexpected disconnect while reading sideband packet
fatal: early EOF
fatal: fetch-pack: invalid index-pack output

対応2 : 最新の履歴だけ取得する

--depth
Create a shallow clone with a history truncated to the specified number of commits. Implies --single-branch unless --no-single-branch is given to fetch the histories near the tips of all branches. If you want to clone submodules shallowly, also pass --shallow-submodules.
Git - git-clone Documentation

# 最新の履歴だけ指定するとクローンはできた
$ git clone --depth 1 https://github.com/user/repo-name.git
Cloning into 'repo-name'...
remote: Enumerating objects: 646, done.
remote: Counting objects: 100% (646/646), done.
remote: Compressing objects: 100% (554/554), done.
Receiving objects: 100% (646/646), 5.36 MiB | 75.00 KiB/s, done.d 0

Resolving deltas: 100% (241/241), done.
# 全部の履歴を取得しようとするとやはりエラー
$ git fetch --unshallow
remote: Enumerating objects: 57317, done.
remote: Counting objects: 100% (57315/57315), done.
remote: Compressing objects: 100% (14462/14462), done.
error: RPC failed; curl 18 transfer closed with outstanding read data remaining
error: 7342 bytes of body are still expected
fetch-pack: unexpected disconnect while reading sideband packet
fatal: early EOF
fatal: fetch-pack: invalid index-pack output

対応3 : ネットワーク環境がいい時に実行する

使っていた時にネットワークが遅かったのですが、後日ネットワークが早くなった時に実行したらエラーにはなりませんでした。
技術的な解決ではないのですが、通信が早い環境で行うのも1つの対策のようです。

他の対応 : リポジトリのサイズを小さくする

やっていないけれど見つけた他の対応方法です。

git gcgit repackを使ってリポジトリのサイズを削減する方法です。
根本解決するには、この対応が良いのかもしれませんが、使ったことがないのでよく調べないとちょっと怖いですね。
というわけで今回はやってはいません。

事象 : RPC failed; curl 92 HTTP/2 stream 7 was not closed cleanly

  • 環境
    • Windows 11 Pro
    • git version 2.42.0.windows.2
# Gitのリポジトリをクローンしたらエラーになった。
$ git clone https://github.com/user/repo-name.git
Cloning into 'repo-name'...
remote: Enumerating objects: 58103, done.
remote: Counting objects: 100% (3115/3115), done.
remote: Compressing objects: 100% (964/964), done.
error: RPC failed; curl 92 HTTP/2 stream 7 was not closed cleanly: CANCEL (err 8)
error: 7194 bytes of body are still expected
fetch-pack: unexpected disconnect while reading sideband packet
fatal: early EOF
fatal: fetch-pack: invalid index-pack output

原因 : 不明

「リポジトリのサイズが大きすぎる」のに通信が遅いとかかもしれないです。

対応 : HTTPのバージョンを下げる

http.version
Use the specified HTTP protocol version when communicating with a server. If you want to force the default. The available and default version depend on libcurl.
Git - git-config Documentation

http.versionを設定することで解決する場合もあるようですが、今回はエラーメッセージが変わるだけでした・・・

# 未設定だった
$ git config --global http.version
# 設定してみる
$ git config --global http.version HTTP/1.1
$ cat ~/.gitconfig | grep -e http -e version
[http]
        version = HTTP/1.1
# エラーメッセージが若干変わった
$ git clone https://github.com/user/repo-name.git
Cloning into 'repo-name'...
remote: Enumerating objects: 58103, done.
remote: Counting objects: 100% (3115/3115), done.
remote: Compressing objects: 100% (970/970), done.
error: RPC failed; curl 18 transfer closed with outstanding read data remaining
error: 2413 bytes of body are still expected
fetch-pack: unexpected disconnect while reading sideband packet
fatal: early EOF
fatal: fetch-pack: invalid index-pack output
3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2