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

net/http: Client.Timeout doesn't work when receiving a response from an incomplete WebSocket handshake #71325

Open
RyougikiMikiya opened this issue Jan 19, 2025 · 5 comments
Labels
BugReport Issues describing a possible bug in the Go implementation. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.

Comments

@RyougikiMikiya
Copy link

Go version

go version go1.23.4 linux/amd64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/root/.cache/go-build'
GOENV='/root/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE='pkg.go'
GOMODCACHE='/root/go/pkg/mod'
GOOS='linux'
GOPATH='/root/go'
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/home/linuxbrew/.linuxbrew/Cellar/go/1.23.4/libexec'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='local'
GOTOOLDIR='/home/linuxbrew/.linuxbrew/Cellar/go/1.23.4/libexec/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.23.4'
GODEBUG=''
GOTELEMETRY='local'
GOTELEMETRYDIR='/root/.config/go/telemetry'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='cc'
CXX='c++'
CGO_ENABLED='1'
GOMOD='/root/gotests/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build670266472=/tmp/go-build -gno-record-gcc-switches'

What did you do?

I encountered a situation where http.Client.Timeout doesn't work as expected when reading response body from an incomplete/fake WebSocket handshake response. Here's a minimal reproduction:
https://go.dev/play/p/i0mxl_6BaZR

What did you see happen?

The client appears to be permanently blocked when reading the response body despite having a client timeout set. The timeout doesn't trigger as expected, and the operation hangs indefinitely.

What did you expect to see?

When reading the response body from an incomplete WebSocket handshake (where server sends handshake headers but no data afterwards), the http.Client.Timeout setting should trigger after the specified timeout duration (5 seconds in this case) while reading the body.

@gabyhelp gabyhelp added the BugReport Issues describing a possible bug in the Go implementation. label Jan 19, 2025
@dr2chase
Copy link
Contributor

@neild @rsc Gaby turned up some interesting looking issues, not sure I am qualified to tell if they are a good match or not.

@dr2chase dr2chase added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jan 21, 2025
@seankhliao seankhliao changed the title net/http Client.Timeout doesn't work when receiving a response from an incomplete WebSocket handshake. net/http: Client.Timeout doesn't work when receiving a response from an incomplete WebSocket handshake Jan 23, 2025
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/646035 mentions this issue: net/http: propagate client timeout to upgraded connections

@neild
Copy link
Contributor

neild commented Feb 1, 2025

I think this is the responsibility of the WebSocket implementation to deal with.

Hijacking an HTTP/1 connection transfers ownership of the net.Conn to the caller of Hijack. If the caller wants to set a deadline, they can do so.

@seankhliao
Copy link
Member

On the server side, there's Hijack / ResponseController to explicitly take control of the underlying connection.

But this report is about the client side, which does not specify any parameters in the request that it expects to be hijacked, and the client / transport implementation automatically hijacks the connection for you on receiving the headers the server sent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BugReport Issues describing a possible bug in the Go implementation. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

6 participants