From ed8def4d9b982a856f7c6ed6257cc997776fc80e Mon Sep 17 00:00:00 2001 From: Zoltan Papp Date: Fri, 7 Jun 2024 16:07:35 +0200 Subject: [PATCH] Protect ws writing in Gorilla ws --- relay/client/dialer/ws/client_conn.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/relay/client/dialer/ws/client_conn.go b/relay/client/dialer/ws/client_conn.go index 698cb9d24..ee3283ecd 100644 --- a/relay/client/dialer/ws/client_conn.go +++ b/relay/client/dialer/ws/client_conn.go @@ -3,6 +3,7 @@ package ws import ( "fmt" "net" + "sync" "time" "github.com/gorilla/websocket" @@ -10,11 +11,12 @@ import ( type Conn struct { *websocket.Conn + mu sync.Mutex } func NewConn(wsConn *websocket.Conn) net.Conn { return &Conn{ - wsConn, + Conn: wsConn, } } @@ -32,7 +34,9 @@ func (c *Conn) Read(b []byte) (n int, err error) { } func (c *Conn) Write(b []byte) (int, error) { + c.mu.Lock() err := c.WriteMessage(websocket.BinaryMessage, b) + c.mu.Unlock() return len(b), err }