Skip to content

Commit 9312e7c

Browse files
committed
fix: check connected clients before broadcasting perf data #1259
1 parent 8996e78 commit 9312e7c

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

api/nginx/websocket.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,17 @@ func (h *NginxPerformanceHub) sendPerformanceDataToClient(client *NginxPerforman
106106

107107
// broadcastPerformanceData sends performance data to all connected clients
108108
func (h *NginxPerformanceHub) broadcastPerformanceData() {
109+
h.mutex.RLock()
110+
111+
// Check if there are any connected clients
112+
if len(h.clients) == 0 {
113+
h.mutex.RUnlock()
114+
return
115+
}
116+
117+
// Only get performance data if there are connected clients
109118
response := performance.GetPerformanceData()
110119

111-
h.mutex.RLock()
112120
for client := range h.clients {
113121
select {
114122
case client.send <- response:

0 commit comments

Comments
 (0)