Closed Ja7ad closed 1 month ago
The error
write tcp4 127.0.0.1:8001->127.0.0.1:59510: write: broken pipe
usually occurs when attempting to write to a closed connection. This can happen if the WebSocket connection is closed by the client or if there is an issue with network connectivity.
The error
write tcp4 127.0.0.1:8001->127.0.0.1:59510: write: broken pipe
usually occurs when attempting to write to a closed connection. This can happen if the WebSocket connection is closed by the client or if there is an issue with network connectivity.
Sure, but after reconnecting, this error intermittently occurred while writing. I changed my code to handle the connection closure, but my problem was not resolved.
func (c *Controller) LiveBlock(ws *websocket.Conn) {
done := make(chan bool)
go func() {
for {
t, _, err := ws.ReadMessage()
if err != nil {
log.Println("Error reading message:", err)
return
}
if t == websocket.CloseMessage {
done <- true
}
}
}()
for {
select {
case <-done:
return
case block := <-c.blockCh:
if err := ws.WriteJSON(block); err != nil {
log.Println(err)
}
}
}
}
I found my issue and fixed it
Bug Description
I send channel received message to
ws.WriteJson
, but after some connect and disconnect get error:How to Reproduce
I get message from channel realtime then write in websocket
Expected Behavior
How to understand how many client connected and how handle this issue don't get this error.
Contrib package Version
v1.3.1
Code Snippet (optional)
Checklist: