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.
This commit is contained in:
Gareth Kirwan
2023-05-01 01:40:53 +01:00
committed by GitHub
parent b20cf75d13
commit 229f965192
2 changed files with 7 additions and 6 deletions

View File

@@ -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

View File

@@ -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