Ubuntu wsl2 git 获得 "The remote end hung up unexpectedly" 大型回购协议

Ubuntu wsl2 git getting "The remote end hung up unexpectedly" on large repos

在 Windows 上 Ubuntu 19.04 的 wsl2 中获得此操作几天。

$ git clone https://github.com/gohugoio/hugo.git
Cloning into 'hugo'...
error: RPC failed; curl 56 GnuTLS recv error (-12): A TLS fatal alert has been received.
fatal: The remote end hung up unexpectedly

四天的威士忌探戈狐步舞……然后我找到了。

最新的 Windows Hyper-V 您的 wifi 驱动程序有问题。您需要从 https://downloadcenter.intel.com/download/28876/Windows-10-Wi-Fi-Drivers-for-Intel-Wireless-Adapters?v=t

获取最新信息

一旦安装了新的驱动程序,您就会惊叹于 git 在 wsl2 中如何完全按照预期的方式工作。我再也回不到生命中的那 5 天了。我希望这会让你失去 5 天的时间。

这是问题所在:https://github.com/microsoft/WSL/issues/4253

2020 年 11 月更新:WSL2 4253 上的最新评论指出:

set MTU to 1350 (same as VPN interface):

sudo ifconfig eth0 mtu 1350
# or
ip link set dev eth0 mtu 1350

检查您的 MTU:

PS C:\> netsh interface ipv4 show subinterface

   MTU  MediaSenseState   Bytes In  Bytes Out  Interface
------  ---------------  ---------  ---------  -------------
4294967295                1          0     117945  Loopback Pseudo-Interface 1
  1500                1  879583365  308029141  Wi-Fi
...
  1500                1    3616963    2778319  vEthernet (WSL)

vs.

➜ ip addr | grep mtu
5: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000

一个Windows 10 build 20231 might be needed to ensure issue 5821 "WSL vEthernet adapter shows up as disconnected"固定了。


B. Agustín Amenábar Larraín explains:

Until this issue I never had heard of MTU, and it was hard for me to believe that was the cause, well it is.

  • I'm having isues when my Pulse Secure VPN is connected and I'm trying to connect to the internal self-hosted Gitlab.
  • SSH traffic to the regular internet is fine.
  • I'm using WSL2 Ubuntu 20.04, if I drop it to WSL1, all works as expected (Same for Debian).

Try upgrading your drivers first, that thidn't work for me.

First open a PowerShell prompt and type:

netsh interface ipv4 show subinterface

You will get an output like the following:

  MTU  MediaSenseState   Bytes In  Bytes Out  Interface
------  ---------------  ---------  ---------  -------------
4294967295                1          0    5974969  Loopback Pseudo-Interface 1
 1500                1  2678641808  213293706  Wi-Fi
 1500                5          0          0  Local Area Connection* 1
 1500                5          0          0  Local Area Connection* 2
 1500                1          0     529702  vEthernet (Default Switch)
 1300                1       2106     509236  vEthernet (WSL)
 1200                1  553027168   20290571  Local Area Connection* 13
 1500                1          0   22759124  VirtualBox Host-Only Network #3
 1500                5          0          0  Bluetooth Network Connection 4

The key is in the Local Area Connection 13 MTU* (The name and value can change from machine to machine), that is the VPN interface. In my case it's 1200 which is why

set MTU to 1350 (same as VPN interface):
sudo ifconfig eth0 mtu 1350

didn't work for me... and I didn't know how to get the VPN Interface MTU.

(I also hated to install ifconfig which is deprecated in favor of ip).

Now that we know, you can change the VPN MTU from Windows it in a PowerShell with Elevated Privileges,

netsh interface ipv4 set subinterface "Local Area Connection* 13" mtu=1400 store=persistent

If you want to skip the next step, you can set it to 1500, but you are leaving no room for the VPN to wrap the packets, for example I have had trouble with Github because of setting it to 1500.

Then, inside your WSL2 distro, you can check your current MTU values with:

❯ ip addr | grep mtu
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
2: bond0: <BROADCAST,MULTICAST,MASTER> mtu 1500 qdisc noop state DOWN group default qlen 1000
3: dummy0: <BROADCAST,NOARP> mtu 1500 qdisc noop state DOWN group default qlen 1000
4: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
5: sit0@NONE: <NOARP> mtu 1480 qdisc noop state DOWN group default qlen 1000

We care about eth0 (the virtual ethernet connection to Windows), you have to set a matching MTU to where you left it in the previous step.

sudo ip link set eth0 mtu 1400

Sadly both settings get resetted every time you start a new VPN session, or restart the WSL2, or even switch from WLAN to LAN.

Leonardo Oliveira adds:

Your solution to the problem was similar to mine, however I changed the Ethernet MTU inside on my WSL2 to the same numbering I saw in windows power shell (Ethernet WSL), and that way it worked for me.