From 6ae350b4e4439af97727b8d3aa89601364f2d244 Mon Sep 17 00:00:00 2001 From: Oliver Date: Mon, 13 Mar 2023 00:09:51 +1100 Subject: [PATCH] concurrent map read :unamused: --- probe.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/probe.go b/probe.go index 16732c7..e8ef415 100644 --- a/probe.go +++ b/probe.go @@ -10,6 +10,7 @@ package main import ( "log" "net/http" + "sync" "github.com/gin-gonic/gin" "github.com/gorilla/websocket" @@ -92,6 +93,8 @@ type ProbeSocketHandler struct { broadcast chan *[]byte upgrader *websocket.Upgrader + + mux sync.Mutex } func (h *ProbeSocketHandler) Run() { @@ -138,7 +141,9 @@ func (h *ProbeSocketHandler) ServeWS(c *gin.Context) { } func (h *ProbeSocketHandler) BroadcastData(data *[]byte) { + h.mux.Lock() for client := range h.clients { client.sendChan <- data } + h.mux.Unlock() }