Skip to content

Context expiration on Read shuts down WebSocket #242

@misberner

Description

@misberner

If the context I pass to (*Conn).Read expires, this shuts down the entire websocket. conn_notjs:160 is at fault here.

This is confusing and severely constraints the ways in which this library can be used. For example, the following is not possible:

for {
  readCtx, cancel := context.WithTimeout(readCtx, 10 * time.Second)
  mt, msg, err := conn.Read(readCtx)
  cancel()
  if err == context.DeadlineExceeded {
    fmt.Println("No message so far. Don't worry, connection is still alive, let's wait another 10s.")
    continue
  }
}

It is also extremely un-idiomatic since contexts communicate expectations/bounds by the caller only, and the effects of their expiration should be local to the call.

The only way to work around this would be to move all reads in a goroutine and communicate the messages read back via a channel, which is.. meh.

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

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy