microsoft / vscode-go

An extension for VS Code which provides support for the Go language. We have moved to https://github.com/golang/vscode-go
Other
5.93k stars 648 forks source link

"Go: Install/Update Tools" with Code and Go extension running in a remote Docker container connects to an unspecified proxy #2752

Closed kidlj closed 5 years ago

kidlj commented 5 years ago

I'm running VSCode and Go extension running in a remote Docker container, it works great. However, when issuing the "Go: Install/Update Tools" command, it seems to connect to an unspecified proxy server, which fails.

Here's the Go extension output:

Installing 1 tool at /go/bin
  gocode

Installing github.com/mdempsky/gocode FAILED

1 tools failed to install.

gocode:
Error: Command failed: /usr/local/go/bin/go get -u -v github.com/mdempsky/gocode
github.com/mdempsky/gocode (download)
# cd .; git clone -- https://github.com/mdempsky/gocode /go/src/github.com/mdempsky/gocode
Cloning into '/go/src/github.com/mdempsky/gocode'...
fatal: unable to access 'https://github.com/mdempsky/gocode/': Failed to connect to 127.0.0.1 port 8118: Connection refused
package github.com/mdempsky/gocode: exit status 128
github.com/mdempsky/gocode (download)
# cd .; git clone -- https://github.com/mdempsky/gocode /go/src/github.com/mdempsky/gocode
Cloning into '/go/src/github.com/mdempsky/gocode'...
fatal: unable to access 'https://github.com/mdempsky/gocode/': Failed to connect to 127.0.0.1 port 8118: Connection refused
package github.com/mdempsky/gocode: exit status 128

I'm kind of familiar with the address 127.0.0.1:8118, which is a v2ray proxy server running on my macOS localhost. The problem is that I'm not specifying any HTTP_PROXY, http_proxy or VSCode http.proxy settings in anywhere, like in .bashrc, .bash_profile, /etc/profile, or in VSCode user/remote container/workspace config files.

Here is the env output from macOS:

$ env
SHELL=/usr/local/bin/bash
XPC_FLAGS=0x0
TERM_PROGRAM_VERSION=421.2
SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.MVA6Z8hh2o/Listeners
TERM_SESSION_ID=E63908B7-9E31-42B7-AA85-27D2A317B087
PWD=/Users/mellon
LOGNAME=mellon
HOME=/Users/mellon
LANG=en_US.UTF-8
TMPDIR=/var/folders/01/v02g0nk97_98qt_4_dsq07hw0000gn/T/
BASH_COMPLETION_COMPAT_DIR=/usr/local/etc/bash_completion.d
TERM=xterm-256color
USER=mellon
SHLVL=1
XPC_SERVICE_NAME=0
KUBECONFIG=:/Users/mellon/.kube/kube:/Users/mellon/.kube/cube:/Users/mellon/.kube/keepalived
PS1=\u@\h:\W \$ 
DOCKER_HOST=tcp://lijian-k8s-node1:2375
LC_ALL=en_US.UTF-8
Apple_PubSub_Socket_Render=/private/tmp/com.apple.launchd.9wZxX9PuYI/Render
PATH=/Users/mellon/go/bin:/Users/mellon/.krew/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin:/Applications/Wireshark.app/Contents/MacOS
GOPATH=/Users/mellon/go
TERM_PROGRAM=Apple_Terminal
_=/usr/bin/env

And the env output from remote docker:

vscode@74de25cb926a:/go/src/go-demo$ env
SHELL=/bin/bash
COLORTERM=truecolor
TERM_PROGRAM_VERSION=1.38.1
APPLICATION_INSIGHTS_NO_DIAGNOSTIC_CHANNEL=true
HOSTNAME=74de25cb926a
PWD=/go/src/go-demo
HOME=/home/vscode
LANG=en_US.UTF-8
LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.zst=01;31:*.tzst=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.wim=01;31:*.swm=01;31:*.dwm=01;31:*.esd=01;31:*.jpg=01;35:*.jpeg=01;35:*.mjpg=01;35:*.mjpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00;36:*.spx=00;36:*.xspf=00;36:
GOLANG_VERSION=1.13
GOROOT=/usr/local/go
TERM=xterm-256color
AMD_ENTRYPOINT=vs/server/remoteExtensionHostProcess
GOPROXY=https://goproxy.cn
SHLVL=1
GO111MODULE=on
VERBOSE_LOGGING=true
PATH=/home/vscode/.vscode-server/bin/b37e54c98e1a74ba89e03073e5a3761284e3ffb0/bin:/go/bin:/usr/local/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
PIPE_LOGGING=true
DEBIAN_FRONTEND=noninteractive
GOPATH=/go
TERM_PROGRAM=vscode
VSCODE_IPC_HOOK_CLI=/tmp/vscode-ipc-2b6641ea-b404-4af0-917d-2903a2db25fa.sock
_=/usr/bin/env

The VSCode user settings:

{
  "editor.tabSize": 2,
    "editor.detectIndentation": false,
    "[markdown]": {
      "editor.tabSize": 4,
      "editor.defaultFormatter": "fcrespo82.markdown-table-formatter",
      // "editor.wordWrap": "wordWrapColumn",
      // "editor.wordWrapColumn": 120,
    },
    "editor.minimap.enabled": false,
    "terminal.integrated.fontSize": 13,
    "breadcrumbs.enabled": true,
    "git.enableSmartCommit": true,
    "explorer.confirmDelete": false,
    "explorer.confirmDragAndDrop": false,
    "extensions.ignoreRecommendations": true,
    "go.testFlags": [
      "-count=1"
    ],
    "editor.wordWrap": "wordWrapColumn",
    "window.zoomLevel": 0,
    "editor.wordWrapColumn": 120,
    "git.inputValidationSubjectLength": 72,
    "markdown.preview.fontSize": 13,
    "editor.fontSize": 13,
    "files.watcherExclude": {
      "**/vendor/**": true
    },
    "workbench.editor.tabCloseButton": "left",
    "go.useLanguageServer": true,
    "terminal.integrated.rendererType": "dom",
}

VSCode remote container settings:

{
    "terminal.integrated.shell.linux": "/bin/bash",
    "go.gopath": "/go",
    "go.inferGopath": true,
  "go.useLanguageServer": true
}

VSCode workspace settings:

{
}

I should also mention that the remote Docker engine that VSCode running on has a proxy setting like this:

$ cat /etc/systemd/system/docker.service.d/http-proxy.conf 
[Service]
Environment="HTTP_PROXY=http://master:8118"
Environment="HTTPS_PROXY=http://master:8118"

, where master is another virtual machine node, with IP address of 10.20.9.10, but even when I turn off this Docker proxy settings, VSCode Go extension still connects to 127.0.0.1:8118, so I don't know if they are related.

P.S. If I issue go get on the remote Docker container manually, it works.

Thanks for any help.

kidlj commented 5 years ago

Sorry, found the 'http_proxy' setting in the remote Docker host user profile.

$ env

NO_PROXY=localhost,127.0.0.1,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16

HTTPS_PROXY=http://127.0.0.1:8118

HTTP_PROXY=http://127.0.0.1:8118

Closed.

kidlj commented 5 years ago

Nope. Even I removed the remote Docker host 'HTTP_PROXY' settings, and set the VSCode remote proxy settings like following, it still connects to 127.0.0.1:8118. I'm still confused where it reads the proxy setting from.

VSCode Remote settings:

{
    "terminal.integrated.shell.linux": "/bin/bash",
    "go.gopath": "/go",
    "go.inferGopath": true,
    "go.useLanguageServer": true,
    "http.proxy": "http://10.20.9.10:8118"
}
kidlj commented 5 years ago
Installing 1 tool at /go/bin
  gocode

Installing github.com/mdempsky/gocode FAILED

1 tools failed to install.

gocode:
Error: Command failed: /usr/local/go/bin/go get -u -v github.com/mdempsky/gocode
github.com/mdempsky/gocode (download)
# cd /go/src/github.com/mdempsky/gocode; git pull --ff-only
fatal: unable to access 'https://github.com/mdempsky/gocode/': Failed to connect to 127.0.0.1 port 8118: Connection refused
package github.com/mdempsky/gocode: exit status 1
github.com/mdempsky/gocode (download)
# cd /go/src/github.com/mdempsky/gocode; git pull --ff-only
fatal: unable to access 'https://github.com/mdempsky/gocode/': Failed to connect to 127.0.0.1 port 8118: Connection refused
package github.com/mdempsky/gocode: exit status 1
kidlj commented 5 years ago

Got it. When VSCode remote extension build the remote container, it will copy local user's .gitconfig to remote container.

Here's the output:

Run: docker cp /Users/mellon/.gitconfig 101f058bd175d53cc243f51a2b90d7be1a66d35e0750d3d2f68a2a0acf7d3c2a:/home/centos/.gitconfig --follow-link

Since I have proxy settings in my local macOS .gitconfig, it retains in remote container, that's why git clone failed.