From 4be21ebd9982dd1dff2c7941fd5b86977d11767c Mon Sep 17 00:00:00 2001 From: nick Date: Wed, 31 Jul 2024 20:03:36 +0900 Subject: [PATCH] fix: fix merge conflict --- node/pkg/dal/api/hub.go | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/node/pkg/dal/api/hub.go b/node/pkg/dal/api/hub.go index 97a06bca4..01d70f5d2 100644 --- a/node/pkg/dal/api/hub.go +++ b/node/pkg/dal/api/hub.go @@ -55,16 +55,17 @@ func (h *Hub) handleClientRegistration() { } func (h *Hub) addClient(conn *websocket.Conn) { - c.mu.RLock() - if _, ok := c.clients[conn]; ok { - c.mu.RUnlock() + h.mu.RLock() + if _, ok := h.clients[conn]; ok { + h.mu.RUnlock() return } - c.mu.RUnlock() + h.mu.RUnlock() h.mu.Lock() defer h.mu.Unlock() + ip := conn.IP() h.clients[conn] = make(map[string]bool) if _, ok := h.connPerIP[ip]; !ok { h.connPerIP[ip] = make([]*websocket.Conn, 0) @@ -92,22 +93,22 @@ func (h *Hub) addClient(conn *websocket.Conn) { } func (h *Hub) removeClient(conn *websocket.Conn) { - c.mu.RLock() - if _, ok := c.clients[conn]; !ok { - c.mu.RUnlock() + h.mu.RLock() + if _, ok := h.clients[conn]; !ok { + h.mu.RUnlock() return } - c.mu.RUnlock() + h.mu.RUnlock() h.mu.Lock() defer h.mu.Unlock() + ip := conn.IP() - for symbol := range h.clients[conn] { delete(h.clients[conn], symbol) } delete(h.clients, conn) - + for i, c := range h.connPerIP[ip] { if c == conn { h.connPerIP[ip] = append(h.connPerIP[ip][:i], h.connPerIP[ip][i+1:]...) @@ -117,7 +118,6 @@ func (h *Hub) removeClient(conn *websocket.Conn) { } } - _ = conn.WriteControl( websocket.CloseMessage, websocket.FormatCloseMessage(websocket.CloseNormalClosure, ""), @@ -156,7 +156,7 @@ func (h *Hub) castSubmissionData(data *dalcommon.OutgoingSubmissionData, symbol if _, ok := h.clients[conn][*symbol]; ok { if err := conn.WriteJSON(*data); err != nil { log.Error().Err(err).Msg("failed to write message") - go func() { c.unregister <- conn }() + go func() { h.unregister <- conn }() } } }