You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
document http client must use context timeout and not timeout on struct #341
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.
changed the title [-]Dial got error "failed to WebSocket dial: response body is not a io.ReadWriteCloser: *http.cancelTimerBody" when set http.DefaultClient.Timeout[/-][+]document http client must use context timeout and not timeout on struct[/+]on Mar 7, 2023
Ah right yea so I'll change the code here to remove the Timeout from *http.Client but right now you have to make sure Timeout is 0 on whatever *http.Client you use with websocket.Dial.
I believe that nothing needs to be done, as context.WithCancel(context.Background()) works perfectly too, I believe the problem in my code is something else, I'm rewriting it.
The bug occurred after closing the connection and reopening.
Thank you for creating this library and being active in the project
Activity
nhooyr commentedon Mar 5, 2023
Ah right, I'll document this.
[-]Dial got error "failed to WebSocket dial: response body is not a io.ReadWriteCloser: *http.cancelTimerBody" when set http.DefaultClient.Timeout[/-][+]document http client must use context timeout and not timeout on struct[/+]mateusfmello commentedon Sep 12, 2023
@nhooyr
Was this implemented in the project?
I'm having the same problem here, but i use
context.WithCancel(context.Background())nhooyr commentedon Sep 12, 2023
Nothing to implement, just an unfortunate quirk of
*http.Client. Please use the context to pass in a timeout.mateusfmello commentedon Sep 12, 2023
Looking at the readme example, I switched to
context.WithTimeout, but the error continuesnhooyr commentedon Sep 12, 2023
Ah right yea so I'll change the code here to remove the Timeout from
*http.Clientbut right now you have to make sure Timeout is0on whatever*http.Clientyou use withwebsocket.Dial.mateusfmello commentedon Sep 13, 2023
I believe that nothing needs to be done, as
context.WithCancel(context.Background())works perfectly too, I believe the problem in my code is something else, I'm rewriting it.The bug occurred after closing the connection and reopening.
Thank you for creating this library and being active in the project
nhooyr commentedon Sep 28, 2023
Oh interesting, I'll definitely test to make sure.
dial.go: Use timeout on HTTPClient properly
nhooyr commentedon Oct 13, 2023
Fixed in dev.