Closed
Description
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.