From ebaa55d63833b4da6fd6841445a98fb60db64575 Mon Sep 17 00:00:00 2001 From: Gareth Kirwan Date: Mon, 5 Feb 2024 13:37:41 +0700 Subject: [PATCH] Websocket: Protect Setup() from races --- exchanges/stream/websocket.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/exchanges/stream/websocket.go b/exchanges/stream/websocket.go index 9e527622b3a..af882464604 100644 --- a/exchanges/stream/websocket.go +++ b/exchanges/stream/websocket.go @@ -103,6 +103,9 @@ func (w *Websocket) Setup(s *WebsocketSetup) error { return errWebsocketSetupIsNil } + w.m.Lock() + defer w.m.Unlock() + if w.IsInitialised() { return fmt.Errorf("%s %w", w.exchangeName, errWebsocketAlreadyInitialised) }