Repository: go
Issue: net: "connectex: invalid argument" when dialing an Artifactory server over IPv6
Labels: OS-Windows,NeedsInvestigation

Working from home on a company-owned laptop (no admin rights) with Windows 10. From the office everything is OK, from home office the situation is different. The GOPROXY URL is IPv6 and then it gets redirected by the server. I can connect just fine to artifactory (the GOPROXY we use) both from shell and from browser, but "go get" fails with "connectex: invalid argument". The error is very vague and hard to debug.

Here you can see the output from curl, proving everything is ok server side:

<details><summary><code>curl -vk https://artifactory.domain.com</code> Output</summary><br><pre>
curl -vk https://artifactory.domain.com

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current

                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0*   Trying ffff:eeee:dddd:cccc::aaa:333:443...

* TCP_NODELAY set

* Connected to artifactory.domain.com (ffff:eeee:dddd:cccc::aaa:333) port 443 (#0)

* ALPN, offering h2

* ALPN, offering http/1.1

* successfully set certificate verify locations:

*   CAfile: C:/PortableGit/mingw64/ssl/certs/ca-bundle.crt

  CApath: none

} [5 bytes data]

* TLSv1.3 (OUT), TLS handshake, Client hello (1):

} [512 bytes data]

* TLSv1.3 (IN), TLS handshake, Server hello (2):

{ [108 bytes data]

* TLSv1.2 (IN), TLS handshake, Certificate (11):

{ [1719 bytes data]

* TLSv1.2 (IN), TLS handshake, Server key exchange (12):

{ [333 bytes data]

* TLSv1.2 (IN), TLS handshake, Server finished (14):

{ [4 bytes data]

* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):

} [70 bytes data]

* TLSv1.2 (OUT), TLS change cipher, Change cipher spec (1):

} [1 bytes data]

* TLSv1.2 (OUT), TLS handshake, Finished (20):

} [16 bytes data]

* TLSv1.2 (IN), TLS handshake, Finished (20):

{ [16 bytes data]

* SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384

* ALPN, server accepted to use http/1.1

* Server certificate:

*  subject: CN=artifactory.domain.com

*  start date: Sep 25 02:47:51 2020 GMT

*  expire date: Sep 24 02:47:51 2024 GMT

*  issuer: DC=loc; DC=A2; CN=LGTSubCA23

*  SSL certificate verify result: unable to get local issuer certificate (20), continuing anyway.

} [5 bytes data]

> GET / HTTP/1.1

> Host: artifactory.domain.com

> User-Agent: curl/7.68.0

> Accept: */*

> 

{ [5 bytes data]

* Mark bundle as not supporting multiuse

< HTTP/1.1 302 Moved Temporarily

< Server: nginx/1.16.1

< Date: Thu, 05 Nov 2020 09:45:45 GMT

< Content-Type: text/html

< Content-Length: 145

< Location: https://artifactory.domain.com/ui/

< Connection: keep-alive

< 

{ [145 bytes data]

100   145  100   145    0     0    523      0 --:--:-- --:--:-- --:--:--   525<html>

<head><title>302 Found</title></head>

<body>

<center><h1>302 Found</h1></center>

<hr><center>nginx/1.16.1</center>

</body>

</html>

 

* Connection #0 to host artifactory.domain.com left intact
</pre></details>

### What version of Go are you using (`go version`)?

<pre>
$ go version

go version go1.15.3 windows/amd64
</pre>

### Does this issue reproduce with the latest release?
Yes


### What operating system and processor architecture are you using (`go env`)?

<details><summary><code>go env</code> Output</summary><br><pre>
$ go env

set GO111MODULE=on

set GOARCH=amd64

set GOBIN=

set GOCACHE=C:\Users\username\AppData\Local\go-build

set GOENV=C:\Users\username\AppData\Roaming\go\env

set GOEXE=.exe

set GOFLAGS= -mod=

set GOHOSTARCH=amd64

set GOHOSTOS=windows

set GOINSECURE=

set GOMODCACHE=C:\Users\username\go\pkg\mod

set GONOPROXY=bitbucket.domain.com

set GONOSUMDB=bitbucket.domain.com/*

set GOOS=windows

set GOPATH=C:\Users\username\go

set GOPRIVATE=bitbucket.domain.com

set GOPROXY=https://username:password@artifactory.domain.com/artifactory/api/go/go-all

set GOROOT=C:\Go

set GOSUMDB=sum.golang.org

set GOTMPDIR=

set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64

set GCCGO=gccgo

set AR=ar

set CC=gcc

set CXX=g++

set CGO_ENABLED=1

set GOMOD=C:\Users\username\go\src\bitbucket.domain.com\go\digicertapi\go.mod

set CGO_CFLAGS=-g -O2

set CGO_CPPFLAGS=

set CGO_CXXFLAGS=-g -O2

set CGO_FFLAGS=-g -O2

set CGO_LDFLAGS=-g -O2

set PKG_CONFIG=pkg-config

set GOGCCFLAGS=-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\Users\username\AppData\Local\Temp\1\go-build705699710=/tmp/go-build -gno-record-gcc-switches

</pre></details>

### What did you do?

<!--
If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.
-->
<pre>go get -u</pre> (or any go get command)


### What did you expect to see?

go modules downloaded


### What did you see instead?
<pre>
go: github.com/google/go-cmp@v0.5.2: Get "https://username:***@artifactory.domain.com/artifactory/api/go/go-all/github.com/google/go-cmp/@v/v0.5.2.mod": dial tcp [ipv6 address]:443: connectex: invalid argument</pre>