vagrant CLI 挂在 Windows 10

vagrant CLI hangs on Windows 10

我在 Windows 10 上使用公司代理后的 vagrant 2.2.5。

所有 CLI 命令都挂起。 让我们用vagrant help来说明我的问题。

vagrant help 需要超过 30 秒。

Measure-Command {start-process vagrant -argumentlist "help" -Wait}


Days              : 0
Hours             : 0
Minutes           : 0
Seconds           : 36
Milliseconds      : 94
Ticks             : 360943091
TotalDays         : 0,000417758207175926
TotalHours        : 0,0100261969722222
TotalMinutes      : 0,601571818333333
TotalSeconds      : 36,0943091
TotalMilliseconds : 36094,3091

vagrant help --debug 显示挂在

DEBUG checkpoint_client: waiting for checkpoint to complete...

以后

INFO runner: Running action: environment_unload #<Vagrant::Action::Builder:0x0000000004b32910>

我注意到如果我断开网络连接(飞行模式,拔下以太网电缆),情况会好很多:

Measure-Command {start-process vagrant -argumentlist "help" -Wait}


Days              : 0
Hours             : 0
Minutes           : 0
Seconds           : 5
Milliseconds      : 14
Ticks             : 50147343
TotalDays         : 5,804090625E-05
TotalHours        : 0,00139298175
TotalMinutes      : 0,083578905
TotalSeconds      : 5,0147343
TotalMilliseconds : 5014,7343

配置代理就更好了:

$env:HTTP_PROXY="http://my.proxy.host:port"
$env:HTTPS_PROXY="http://my.proxy.host:port"


Measure-Command {start-process vagrant -argumentlist "help" -Wait}


Days              : 0
Hours             : 0
Minutes           : 0
Seconds           : 2
Milliseconds      : 24
Ticks             : 20249878
TotalDays         : 2,34373587962963E-05
TotalHours        : 0,000562496611111111
TotalMinutes      : 0,0337497966666667
TotalSeconds      : 2,0249878
TotalMilliseconds : 2024,9878

相比之下,在 WSL(Windows Subsytem For Linux)中,它在所有情况下都快得多(不依赖于连接):

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 19.04
Release:        19.04
Codename:       disco

$ time vagrant help
(...)
real    0m1.043s
user    0m0.500s
sys     0m0.469s

由于 vagrant 在我的 WSL Ubuntu 中是 2.0.2 版,我也在 Windows 上测试了这个版本。我有同样的行为。

问题出在网络访问上。
Vagrant 的支持在 issue 我打开时解释说 vagrant 会定期检查新版本以在有新版本时通知用户。
如果网络访问缓慢或挂起,那么每个命令都会等待它,因为 vagrant 会尝试直到得到答案。
只有这样,它会等待一段时间再试。
要禁用此轮询,只需设置 environment variable VAGRANT_CHECKPOINT_DISABLE.