Git: Failed sending HTTP2 data解决办法
written in 2021 — details may be outdated

最近一段时间发现手中的Debian机器在Git Clone的时候出现奇怪的错误,经过一番Google,最终发现是libcurl3-gnutls这个库的bug。
2021-10-01 Update: Buster-backports仍未修复此问题,但是Bullseye已经合入了新的版本,修复了此问题。
2021-06-19 Update: 修复补丁仍未合入backports中,问题的原因似乎是libcurl-guntls的TLSv1.3实现有问题。
2021-08-03 Update: Curl 7.76.1修复了此问题,但尚未合并进入Buster backports, Bullseye也未更新。
现象#
在使用https协议进行git clone的时候,出现HTTP2报错
xxxxx$> git clone https://github.com/TechMinerApps/portierCloning into 'portier'...fatal: unable to access 'https://github.com/TechMinerApps/portier/': Failed sending HTTP2 data起初我以为和GitHub即将禁止Basic Auth的https操作有关,但是使用GIT_TRACE2=2 GIT_CURL_VERBOSE=1进行调试的时候,发现是curl中的问题。
20:35:22.968833 http.c:756 == Info: Couldn't find host github.com in the .netrc file; using defaults20:35:22.973819 http.c:756 == Info: Trying 192.30.255.113:443...20:35:23.144791 http.c:756 == Info: Connected to github.com (192.30.255.113) port 443 (#0)20:35:23.168789 http.c:756 == Info: found 411 certificates in /etc/ssl/certs20:35:23.169022 http.c:756 == Info: ALPN, offering h220:35:23.169092 http.c:756 == Info: ALPN, offering http/1.120:35:23.341023 http.c:756 == Info: SSL connection using TLS1.3 / ECDHE_RSA_AES_128_GCM_SHA25620:35:23.341674 http.c:756 == Info: server certificate verification OK20:35:23.341682 http.c:756 == Info: server certificate status verification SKIPPED20:35:23.341750 http.c:756 == Info: common name: github.com (matched)20:35:23.341754 http.c:756 == Info: server certificate expiration date OK20:35:23.341757 http.c:756 == Info: server certificate activation date OK20:35:23.341763 http.c:756 == Info: certificate public key: EC/ECDSA20:35:23.341766 http.c:756 == Info: certificate version: #320:35:23.341786 http.c:756 == Info: subject: C=US,ST=California,L=San Francisco,O=GitHub\, Inc.,CN=github.com20:35:23.341791 http.c:756 == Info: start date: Thu, 25 Mar 2021 00:00:00 GMT20:35:23.341795 http.c:756 == Info: expire date: Wed, 30 Mar 2022 23:59:59 GMT20:35:23.341807 http.c:756 == Info: issuer: C=US,O=DigiCert\, Inc.,CN=DigiCert High Assurance TLS Hybrid ECC SHA256 2020 CA120:35:23.341818 http.c:756 == Info: ALPN, server accepted to use h220:35:23.341851 http.c:756 == Info: Using HTTP2, server supports multi-use20:35:23.341853 http.c:756 == Info: Connection state changed (HTTP/2 confirmed)20:35:23.341858 http.c:756 == Info: Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=020:35:23.341866 http.c:756 == Info: Failed sending HTTP2 data20:35:23.341873 http.c:756 == Info: Connection #0 to host github.com left intact随即Google了一番后找到了Debian Bug Tracker中的一个提交 libcurl3-gnutls from debian backports breaks git http operations
原文如下,完全一模一样。
Package: libcurl3-gnutlsVersion: 7.74.0-1.2~bpo10+1Severity: important|X-Debbugs-CC: |debian-backports@lists.debian.org
After upgrading the Debian system from "backports" any git http operations (clone/fetch ...) has stopped working, bringing libcurl3-gnutls to the previous version (7.74.0-1.2~bpo10+1) fix the problem:
Output of git command> git clone https://github.com/git/gitCloning into 'git'...fatal: unable to access 'https://github.com/git/git/': Failed sending HTTP2 data>
-- apt-cache policy libcurl3-gnutlslibcurl3-gnutls: Installato: 7.74.0-1.2~bpo10+1 Candidato: 7.74.0-1.2~bpo10+1 Tabella versione: *** 7.74.0-1.2~bpo10+1 100 100 https://deb.debian.org/debian buster-backports/main amd64 Packages 100 /var/lib/dpkg/status 7.64.0-4+deb10u2 500 500 https://deb.debian.org/debian-security buster/updates/main amd64 Packages 7.64.0-4+deb10u1 500 500 https://deb.debian.org/debian buster/main amd64 Packages
-- Extra detailed informations:- Output of GIT_CURL_VERBOSE=1 GIT_TRACE2=1 git clone https://github.com/git/git13:03:36.251941 common-main.c:48 version 2.29.213:03:36.251960 common-main.c:49 start git clone https://github.com/git/git13:03:36.251981 git.c:445 cmd_name clone (clone)13:03:36.252185 repository.c:130 worktree /tmp/gh/gitClone in 'git' in corso...13:03:36.253276 run-command.c:735 child_start[0] git remote-https origin https://github.com/git/git13:03:36.254468 common-main.c:48 version 2.29.213:03:36.254485 common-main.c:49 start /usr/lib/git-core/git remote-https origin https://github.com/git/git13:03:36.254572 git.c:723 cmd_name _run_dashed_ (clone/_run_dashed_)13:03:36.254586 run-command.c:735 child_start[0] git-remote-https origin https://github.com/git/git13:03:36.259050 common-main.c:48 version 2.29.213:03:36.259065 common-main.c:49 start /usr/lib/git-core/git-remote-https origin https://github.com/git/git13:03:36.259138 repository.c:130 worktree /tmp/gh13:03:36.259176 remote-curl.c:1482 cmd_name remote-curl (clone/_run_dashed_/remote-curl)13:03:36.259581 http.c:756 == Info: Couldn't find host github.com in the .netrc file; using defaults13:03:36.469244 http.c:756 == Info: Trying 140.82.121.3:443...13:03:36.520476 http.c:756 == Info: Connected to github.com (140.82.121.3) port 443 (#0)13:03:36.544248 http.c:756 == Info: found 381 certificates in /etc/ssl/certs13:03:36.544365 http.c:756 == Info: ALPN, offering h213:03:36.544371 http.c:756 == Info: ALPN, offering http/1.113:03:36.595957 http.c:756 == Info: SSL connection using TLS1.3 / ECDHE_RSA_AES_128_GCM_SHA25613:03:36.596671 http.c:756 == Info: server certificate verification OK13:03:36.596680 http.c:756 == Info: server certificate status verification SKIPPED13:03:36.596778 http.c:756 == Info: common name: github.com (matched)13:03:36.596786 http.c:756 == Info: server certificate expiration date OK13:03:36.596790 http.c:756 == Info: server certificate activation date OK13:03:36.596799 http.c:756 == Info: certificate public key: EC/ECDSA13:03:36.596804 http.c:756 == Info: certificate version: #313:03:36.596838 http.c:756 == Info: subject: C=US,ST=California,L=San Francisco,O=GitHub\, Inc.,CN=github.com13:03:36.596854 http.c:756 == Info: start date: Thu, 25 Mar 2021 00:00:00 GMT13:03:36.596868 http.c:756 == Info: expire date: Wed, 30 Mar 2022 23:59:59 GMT13:03:36.596884 http.c:756 == Info: issuer: C=US,O=DigiCert\, Inc.,CN=DigiCert High Assurance TLS Hybrid ECC SHA256 2020 CA113:03:36.596914 http.c:756 == Info: ALPN, server accepted to use h213:03:36.596955 http.c:756 == Info: Using HTTP2, server supports multi-use13:03:36.596960 http.c:756 == Info: Connection state changed (HTTP/2 confirmed)13:03:36.596974 http.c:756 == Info: Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=013:03:36.596984 http.c:756 == Info: Failed sending HTTP2 data13:03:36.596993 http.c:756 == Info: Connection #0 to host github.com left intact13:03:36.597168 usage.c:64 error impossibile accedere a 'https://github.com/git/git/': Failed sending HTTP2 datafatal: impossibile accedere a 'https://github.com/git/git/': Failed sending HTTP2 data13:03:36.597194 usage.c:68 exit elapsed:0.338490 code:12813:03:36.597203 trace2/tr2_tgt_normal.c:123 atexit elapsed:0.338501 code:12813:03:36.598095 run-command.c:990 child_exit[0] pid:179509 code:128 elapsed:0.34349713:03:36.598114 git.c:745 exit elapsed:0.343919 code:12813:03:36.598155 trace2/tr2_tgt_normal.c:123 atexit elapsed:0.343959 code:12813:03:36.598389 transport-helper.c:581 exit elapsed:0.346748 code:12813:03:36.598639 trace2/tr2_tgt_normal.c:123 atexit elapsed:0.347003 code:128解决方法#
既然是Debian官方源中的问题,那除了等官方解决以外,就只能降级这个库了。
降级到stable,也就是buster的命令如下。APT会自动降级有依赖关系的库,如libcurl4
2021-10-01 Update:Debian 11发布后Buster不再是Stable,因此在Debian 10遇到此问题需要降级到buster或者oldstable,推荐升级至Debian 11解决此问题。
# Downgrade commandsudo apt reinstall libcurl3-gnutls/buster