Skip to content

document http client must use context timeout and not timeout on struct #341

Closed

Description

@yihexi

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.

Activity

  1. nhooyr commented on Mar 5, 2023

    @nhooyr
    Contributor

    Ah right, I'll document this.

  2. 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
  3. mateusfmello commented on Sep 12, 2023

    @mateusfmello

    @nhooyr

    Was this implemented in the project?

    I'm having the same problem here, but i use context.WithCancel(context.Background())

  4. nhooyr commented on Sep 12, 2023

    @nhooyr
    Contributor

    Nothing to implement, just an unfortunate quirk of *http.Client. Please use the context to pass in a timeout.

  5. mateusfmello commented on Sep 12, 2023

    @mateusfmello

    Looking at the readme example, I switched to context.WithTimeout, but the error continues

  6. nhooyr commented on Sep 12, 2023

    @nhooyr
    Contributor

    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.

  7. mateusfmello commented on Sep 13, 2023

    @mateusfmello

    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

  8. added this to the v1.8.8 milestone on Sep 28, 2023
  9. nhooyr commented on Sep 28, 2023

    @nhooyr
    Contributor

    Oh interesting, I'll definitely test to make sure.

  10. added a commit that references this issue on Oct 13, 2023
    b4b86b9
  11. nhooyr commented on Oct 13, 2023

    @nhooyr
    Contributor

    Fixed in dev.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions