From 229f965192000331ddba1a5a834b2115dd4990c9 Mon Sep 17 00:00:00 2001 From: Gareth Kirwan Date: Mon, 1 May 2023 01:40:53 +0100 Subject: [PATCH] OKX: Fix authenticated websocket blocking during login (#1174) The channels for the ws multiplexer weren't made; so any interaction with it would block. Tests passed because they invasively setup the multiplexer. There are quite a few architectural risks with this implementation pattern, such as leaking an uncancellable goro in a for-select loop. Ideally WsConnect should take a cancellable context and any selects should watch for ctx.Done() That's a very invasive and pervasive change though, so this fix is as minimal and atomic as possible. Will consider opening a PR for cancellable context or improving this multiplexer pattern. --- exchanges/okx/okx_test.go | 6 ------ exchanges/okx/okx_wrapper.go | 7 +++++++ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/exchanges/okx/okx_test.go b/exchanges/okx/okx_test.go index fb6d0ed9..68ca68af 100644 --- a/exchanges/okx/okx_test.go +++ b/exchanges/okx/okx_test.go @@ -48,12 +48,6 @@ func TestMain(m *testing.M) { exchCfg.API.Credentials.Key = apiKey exchCfg.API.Credentials.Secret = apiSecret exchCfg.API.Credentials.ClientID = passphrase - ok.WsResponseMultiplexer = wsRequestDataChannelsMultiplexer{ - WsResponseChannelsMap: make(map[string]*wsRequestInfo), - Register: make(chan *wsRequestInfo), - Unregister: make(chan string), - Message: make(chan *wsIncomingData), - } ok.SetDefaults() if apiKey != "" && apiSecret != "" && passphrase != "" { exchCfg.API.AuthenticatedSupport = true diff --git a/exchanges/okx/okx_wrapper.go b/exchanges/okx/okx_wrapper.go index 6131e4a2..80d81950 100644 --- a/exchanges/okx/okx_wrapper.go +++ b/exchanges/okx/okx_wrapper.go @@ -192,6 +192,13 @@ func (ok *Okx) Setup(exch *config.Exchange) error { return err } + ok.WsResponseMultiplexer = wsRequestDataChannelsMultiplexer{ + WsResponseChannelsMap: make(map[string]*wsRequestInfo), + Register: make(chan *wsRequestInfo), + Unregister: make(chan string), + Message: make(chan *wsIncomingData), + } + wsRunningEndpoint, err := ok.API.Endpoints.GetURL(exchange.WebsocketSpot) if err != nil { return err