Open AndrewYEEE opened 1 month ago
I have the idea to remove ws object, but I couldn't prove whether the ws object obtained by server.connections[] is the same as the one to be removed.
func (server *Server) writePump(ws *WebSocket) {
conn := ws.connection
for {
select {
case data, ok := <-ws.outQueue:
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
//delete chargepoint ws
server.connMutex.Lock()
if _, ok := server.connections[ws.id]; ok {
delete(server.connections, ws.id) // is same?
log.Infof("closed connection to %s", ws.ID())
if server.disconnectedHandler != nil {
server.disconnectedHandler(ws)
}
}
server.connMutex.Unlock()
return
}
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?