不安定なネットワークでgit cloneが通らないときのSSHを使った解決策 (error: RPC failed)
不安定なネットワークでは,HTTPによるgit cloneが通らないことがあります.
また,以下のようにcmake内でエラーになることもあります.
[ 11%] Performing download step (git clone) for 'openjtalk-populate'
Cloning into 'openjtalk-src'...
error: RPC failed; curl 92 HTTP/2 stream 5 was not closed cleanly: CANCEL (err 8)
error: 8006 bytes of body are still expected
fetch-pack: unexpected disconnect while reading sideband packet
fatal: early EOF
fatal: fetch-pack: invalid index-pack output
Cloning into 'openjtalk-src'...
error: RPC failed; curl 92 HTTP/2 stream 5 was not closed cleanly: CANCEL (err 8)
error: 5039 bytes of body are still expected
fetch-pack: unexpected disconnect while reading sideband packet
fatal: early EOF
fatal: fetch-pack: invalid index-pack output
Cloning into 'openjtalk-src'...
error: RPC failed; curl 92 HTTP/2 stream 5 was not closed cleanly: CANCEL (err 8)
error: 2508 bytes of body are still expected
fetch-pack: unexpected disconnect while reading sideband packet
fatal: early EOF
fatal: fetch-pack: invalid index-pack output
Had to git clone more than once: 3 times.
CMake Error at openjtalk-subbuild/openjtalk-populate-prefix/tmp/openjtalk-populate-gitclone.cmake:50 (message):
Failed to clone repository: 'https://github.com/VOICEVOX/open_jtalk.git'
そのような場合,以下のページで挙げられているように,HTTP/1.1に切り替える,postBufferを増やす,プロトコルをSSHに変えるなどの方法があります.
ここでは筆者が試したことがあるSSHに絞って説明します.もし公開鍵を登録していない場合,この方法は使えない可能性があるので注意してください.
SSHを使った解決策
筆者は個人的な好みでSSHに切り替える方法を採っており,過去に遭遇した2回はこの方法で成功しています.
単純なgit clone
であればURLをSSHに切り替えるだけです.
しかし,cmake等で依存先がURLをHTTPで指定している場合には,以下の内容を一時的に~/.gitconfig
に追記することで,グローバルにHTTPからSSHに切り替える必要があります:
[url "ssh://[email protected]/"]
insteadOf = https://github.com/
[url "ssh://[email protected]/"]
insteadOf = https://gitlab.com/
[url "ssh://[email protected]/"]
insteadOf = https://bitbucket.org/
なお,面倒を生む可能性があるので,作業が終わったらコメントアウト等で設定を戻すのを忘れないようにしてください.