简体   繁体   English

Golang TLS 握手超时,影响 go 获取和 go 代码

[英]Golang TLS handshake timeout, affecting go get and go code

Golang can no longer complete TLS handshakes on my mac (Catalina, but this issue was present on Mojave first). Golang 不能再在我的 mac 上完成 TLS 握手(Catalina,但这个问题首先出现在 Mojave 上)。

I've first noticed that this was occurring with failures to go get :我首先注意到这是由于go get失败而发生的:

unrecognized import path "golang.org/x/text": https fetch: Get "https://golang.org/x/text?go-get=1": net/http: TLS handshake timeout

But I've also confirmed that this is affect golang code as well.但我也确认这也会影响 golang 代码。 Here's a basic example I expect to work:这是我希望工作的一个基本示例:

package main

import (
    "fmt"
    "net/http"
)

func main() {
    resp, err := http.Get("https://google.com")
    fmt.Printf("%v, %v\n", resp, err)
}

If I save this file as main.go and run it, I get the same error that I see from go get :如果我将此文件保存为main.go并运行它,我会得到与从go get看到的相同的错误:

<nil>, Get "https://google.com": net/http: TLS handshake timeout

I can't figure out where I'm going wrong - https sites work fine on my browser, and when I use the Python requests package (or curl) I can access TLS sites just fine.我不知道哪里出错了 - https 站点在我的浏览器上运行良好,当我使用 Python requests package 时,可以正常访问 ITLS 站点(或 curl 站点)。 It appears that somehow this is a go-specific failure.似乎这是一个特定于go的失败。

Here's the output of go env for completeness:为了完整起见,这是go env的 output :

GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/nickchadwick/Library/Caches/go-build"
GOENV="/Users/nickchadwick/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/nickchadwick/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/l9/r8jjmhm13hvcpwppdt9sklm00000gn/T/go-build865222134=/tmp/go-build -gno-record-gcc-switches -fno-common"

Any hints on solving this would be greatly appreciated!任何有关解决此问题的提示将不胜感激! Not being able to go get things is a huge bummer.无法go get东西真是太可惜了。

After narrowing it down to a macOS problem, this fixed it: clean up the old Keychain Access System Certificates.在将其缩小到 macOS 问题后, 解决了它:清理旧的钥匙串访问系统证书。

I ran into something similar.我遇到了类似的事情。 When I build the binary on Mac without the CGO_ENABLED flag it seems to work.当我在没有CGO_ENABLED标志的情况下在 Mac 上构建二进制文件时,它似乎可以工作。 Just adding CGO_ENABLED env var during the build causes this issue.只需在构建期间添加CGO_ENABLED就会导致此问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM