2019-10-09に更新

Proxy 下で vscode の WSL 拡張へ接続できない

Windows 上の Visual Studio Code (以下、 vscode) で、WSL 上のファイルやシェルを使えるようになる、 Remote - WSL 拡張機能。

これを、プロキシ環境下でインストールしたり更新したりすると、 vscode から WSL 環境ににアクセスするときに、

VS Code Server for WSL closed unexpectedly.
Check WSL terminal for mor details.

とエラーになってしまう。

WSL ターミナルのログを見てみると、だいたい以下のようになっていて、どうやら update.code.visualstudio.com から VS Code Server の更新版のファイルをダウンロードするのに失敗しているように見える。

Starting VS Code Server inside WSL (default distro)
Extension version: 0.39.5, Windows build: 17763. Multi distro support: disabled. WSL path support: enabled
Probing if server is already installed: C:\WINDOWS\System32\wsl.exe  -e sh -c "[ -d ~/.vscode-server/bin/3db7e09f3b61f915d03bbfa58e258d6eee843f35 ] && echo found || echo missing"
No server install found on WSL, downloading server on client side: C:\Users\user\AppData\Local\Temp\vscode-remote-wsl\3db7e09f3b61f915d03bbfa58e258d6eee843f35\vscode-server-linux-x64.tar.gz
Unable to detect if server is already installed: Error: connect ECONNREFUSED 104.42.78.153:443
Launching C:\WINDOWS\System32\wsl.exe sh -c '"$VSCODE_WSL_EXT_LOCATION/scripts/wslServer.sh" 3db7e09f3b61f915d03bbfa58e258d6eee843f35 stable .vscode-server 0  --disable-telemetry' in c:\Users\user\.vscode\extensions\ms-vscode-remote.remote-wsl-0.39.5
WSL version: 4.4.0-17763-Microsoft 
Updating server...
Updating VS Code Server to version 3db7e09f3b61f915d03bbfa58e258d6eee843f35
Removing previous installation...
Downloading:     
Failed
--2019-09-11 20:50:12--  https://update.code.visualstudio.com/commit:3db7e09f3b61f915d03bbfa58e258d6eee843f35/server-linux-x64/stable
Resolving update.code.visualstudio.com (update.code.visualstudio.com)... 104.42.78.153
Connecting to update.code.visualstudio.com (update.code.visualstudio.com)|104.42.78.153|:443... 
failed: Connection refused.
ERROR: Failed to download https://update.code.visualstudio.com/commit:3db7e09f3b61f915d03bbfa58e258d6eee843f35/server-linux-x64/stable to ~/.vscode-server/bin/3db7e09f3b61f915d03bbfa58e258d6eee843f35-xxxxxxxxxx.tar.gz
VS Code Server for WSL closed unexpectedly.
For help with startup problems, go to
[https://code.visualstudio.com/docs/remote/troubleshooting#_wsl-tips](https://code.visualstudio.com/docs/remote/troubleshooting#_wsl-tips)

どう解決したものか。


そもそも wget でダウンロードができる状態なのか

拡張機能の GitHub プロジェクト上の Issue によると、内部的には wget でファイルをダウンロードしているらしい。
https://github.com/microsoft/vscode-remote-release/issues/78
https://github.com/microsoft/vscode-remote-release/issues/79

.bashrc で http_proxy, HTTP_PROXY, https_proxy, HTTPS_PROXY 全ての環境変数にプロキシの URL を設定しているので、 wget に対してプロキシの情報は渡っているはずなのだが。。。

とりあえず WSL を起動して、 書き込み権限がある適当なディレクトリで、エラーになっているファイルのダウンロードを wget https://update.code.visualstudio.com/commit:3db7e09f3b61f915d03bbfa58e258d6eee843f35/server-linux-x64/stable で試してみて、 成功するか試してみよう。

私の場合、 以下のような初歩的なミスでダウンロードに失敗していた。

  • HTTP_PROXY と HTTPS_PROXY の大文字の環境変数にしか設定しておらず、 wget がプロキシを認識してくれなかった。
    curl とかはどっちでもイケるから、気づくのに時間がかかった。
  • 何故か ~/.wget-hsts のパーミッションが 666 に書き換わっていて、 wget のセキュリティエラーでダウンロードに失敗している事があった。
  • カレントディレクトリが /mnt/c/ になっていて、ダウンロードしたファイルの書き込めなかった。

それでもダウンロードに失敗する

以下の記事によると、 Windows 側から WSL Remote の VS Code Server を起動するとき、 .bash_profile や .bashrc, .profile などを読んでくれないらしい。
https://github.com/microsoft/vscode-remote-release/issues/432
このため、環境変数でプロキシを設定しても反映されないようだ。

以下のどちらかを行うと、この問題を回避できる。

  • #79#issuecomment-503989625 のコメントのように、 ~/.wgetrc にプロキシの設定を書く。
    • http_proxy と https_proxy だけ設定すればよいはず。 check_certificate = off をむやみに設定するのはセキュリティ上良くない。
  • いったんすべての VS Code を終了させ、 WSL のコンソール上で code と実行し、 Windows の VS Code を起動する。
    • このとき、 WSL 側に Linux 版の VS Code がインストールされていると、そちらが起動してしまうのでダメ。

正直、どちらが良いかは一長一短だ。

.bashrc.wgetrc などあちこちにプロキシの設定を書くと管理が大変だし、
VS Code Server が更新されるたびに WSL 側から VS Code を実行するのは手間だ。

幸い、 #79#issuecomment-504368316 によると、 今後のバージョンでは VS Code Server のダウンロードを Windows 側で行うように更新する予定のようだ。
それまでの間は逐一 WSL 側から VS Code を実行する方法で回避するのでも良いかもしれない。

しかし、少なくとも現時点のバージョンである VS Code 1.38.0 + Remote - WSL 0.39.5 の組み合わせでは、そうなっていない。

Originally published at aquasoftware.net
ツイッターでシェア
みんなに共有、忘れないようにメモ

advanceboy

Crieitは誰でも投稿できるサービスです。 是非記事の投稿をお願いします。どんな軽い内容でも投稿できます。

また、「こんな記事が読みたいけど見つからない!」という方は是非記事投稿リクエストボードへ!

有料記事を販売できるようになりました!

こじんまりと作業ログやメモ、進捗を書き残しておきたい方はボード機能をご利用ください。
ボードとは?

コメント