Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

go: go1.21 version cause gorilla/websocket failed #68522

Closed
cuiweixie opened this issue Jul 19, 2024 · 4 comments
Closed

go: go1.21 version cause gorilla/websocket failed #68522

cuiweixie opened this issue Jul 19, 2024 · 4 comments

Comments

@cuiweixie
Copy link
Contributor

cuiweixie commented Jul 19, 2024

Go version

go version go1.22.4 darwin/arm64

Output of go env in your module/workspace:

GO111MODULE='on'
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/xiecui/Library/Caches/go-build'
GOENV='/Users/xiecui/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOMODCACHE='/Users/xiecui/code/go/gopath/pkg/mod'
GONOSUMDB='on'
GOOS='darwin'
GOPATH='/Users/xiecui/code/go/gopath'
GOPROXY='https://goproxy.cn,direct'
GOROOT='/Users/xiecui/code/go/go1.22.4/go'
GOSUMDB='off'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/Users/xiecui/code/go/go1.22.4/go/pkg/tool/darwin_arm64'
GOVCS='*:all'
GOVERSION='go1.22.4'
GCCGO='gccgo'
AR='ar'
CC='clang'
CXX='clang++'
CGO_ENABLED='1'
GOMOD='/Volumes/Elements/code/go/broker/my_test/go.mod'
GOWORK='off'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/d2/82q9pj7x33gc7m0xkpkx3p3w0000gn/T/go-build162556822=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

go.mod

module github.com/cuiweixie/websocket_test

go 1.21

require github.com/gorilla/websocket v1.5.3 // indirect

wss.go

package main

import (
	"log"
	"net/http"

	"github.com/gorilla/websocket"
)

func main() {
	webURL := "wss://wspap.okx.com:8443/ws/v5/public"

	header := http.Header{}
	var dialer websocket.Dialer
	_, _, err := dialer.Dial(webURL, header)
	if err != nil {
		log.Fatalf("dial failed: %v", err)
	}
	log.Println("connection ok")
}

go run wss.go

What did you see happen?

2024/07/19 19:01:13 dial failed: websocket: bad handshake
exit status 1

What did you expect to see?

if change go mod to:

module github.com/cuiweixie/websocket_test

go 1.22

require github.com/gorilla/websocket v1.5.3 // indirect

will result in:

2024/07/19 19:01:39 connection ok
@cuiweixie
Copy link
Contributor Author

It's strange that using go1.21 doesn't work, but go1.22 or later does.

@seankhliao
Copy link
Member

I think this is controlled by the GODEBUG setting tlsrsakex where the default changed from enabled in go1.21 to disabled in go1.22.
I don't think there's anything to do here as the new behavior is more correct and we aren't going to change the default GODEBUG for a previous version.

main » GODEBUG=tlsrsakex=1 go1.22.5 run .
2024/07/19 12:18:46 dial failed: websocket: bad handshake
exit status 1


main » GODEBUG=tlsrsakex=0 go1.22.5 run . 
2024/07/19 12:18:56 connection ok

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Jul 19, 2024
@cuiweixie
Copy link
Contributor Author

thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants