websocket icon indicating copy to clipboard operation
websocket copied to clipboard

Dial got error "failed to WebSocket dial: response body is not a io.ReadWriteCloser: *http.cancelTimerBody" when set http.DefaultClient.Timeout

Open yihexi opened this issue 3 years ago • 0 comments

when I set http.DefaultClient.Timeout = time.Second * 10, websocket.Dial will get an error "failed to WebSocket dial: response body is not a io.ReadWriteCloser: *http.cancelTimerBody"

verson: nhooyr.io/websocket v1.8.7

this is because in the dial.go line 128: rwc, ok := respBody.(io.ReadWriteCloser), it convert respBody to an io.ReadWriteCloser, I think it should be rwc, ok := respBody.(io.ReadCloser).

in general, respBody is a *http.readWriteCloserBody, but if http.DefaultClient.Timeout is set, it will be a *http.cancelTimerBody, which is just an io.ReadCloser.

yihexi avatar Jun 02 '22 02:06 yihexi