Skip to content

Commit

Permalink
fix: fix merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
nick-bisonai committed Jul 31, 2024
1 parent 4c7f4a1 commit 4be21eb
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions node/pkg/dal/api/hub.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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:]...)
Expand All @@ -117,7 +118,6 @@ func (h *Hub) removeClient(conn *websocket.Conn) {
}
}


_ = conn.WriteControl(
websocket.CloseMessage,
websocket.FormatCloseMessage(websocket.CloseNormalClosure, ""),
Expand Down Expand Up @@ -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 }()
}
}
}
Expand Down

0 comments on commit 4be21eb

Please sign in to comment.