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
Sorry I dont understand why ws.outQueue is need to check that Channel is closed ?
This will cause writePump closed but server.connections still retains the ws object (ws.connection still work).
And
Why doesn't ws.pingMessage need to check if the Channel closed unexpectedly?
func (server *Server) writePump(ws *WebSocket) {
conn := ws.connection
for {
select {
case data, ok := <-ws.outQueue:
_ = conn.SetWriteDeadline(time.Now().Add(server.timeoutConfig.WriteWait))
if !ok {
// Unexpected closed queue, should never happen
server.error(fmt.Errorf("output queue for socket %v was closed, forcefully closing", ws.id))
// Don't invoke cleanup
return **//<===== will exit writePump(), but server.connections still retains the WS object !!!**
}
// Send data
err := conn.WriteMessage(websocket.TextMessage, data)
if err != nil {
server.error(fmt.Errorf("write failed for %s: %w", ws.ID(), err))
// Invoking cleanup, as socket was forcefully closed
server.cleanupConnection(ws)
return
}
log.Debugf("written %d bytes to %s", len(data), ws.ID())
case ping := <-ws.pingMessage:
**// why don't need check channel closed unexpectedly?**
_ = conn.SetWriteDeadline(time.Now().Add(server.timeoutConfig.WriteWait))
err := conn.WriteMessage(websocket.PongMessage, ping)
if err != nil {
server.error(fmt.Errorf("write failed for %s: %w", ws.ID(), err))
// Invoking cleanup, as socket was forcefully closed
server.cleanupConnection(ws)
return
}
log.Debugf("pong sent to %s", ws.ID())
...
The text was updated successfully, but these errors were encountered:
AndrewYEEE
changed the title
Why ws.outQueue is need to check that Channel is closed and return ?
Why ws.outQueue is need to check that Channel is closed ?
Oct 26, 2024
AndrewYEEE
changed the title
Why ws.outQueue is need to check that Channel is closed ?
Why ws.outQueue is need to check if the Channel is closed?
Oct 26, 2024
Sorry I dont understand why ws.outQueue is need to check that Channel is closed ?
This will cause writePump closed but server.connections still retains the ws object (ws.connection still work).
And
Why doesn't ws.pingMessage need to check if the Channel closed unexpectedly?
The text was updated successfully, but these errors were encountered: