From ca9efe7275787b34797e6779514aab85457fe3a8 Mon Sep 17 00:00:00 2001 From: Ryan O'Hara-Reid Date: Fri, 17 May 2024 15:16:02 +1000 Subject: [PATCH] currency/manager: remove deadlock potential in concurrent operations (#1545) * currency/manager: remove deadlock potential in concurrent operations * fix kucoin test, lets see what this does shalllllll weeeeee. * another fix in the deep dark depths --------- Co-authored-by: Ryan O'Hara-Reid --- currency/manager.go | 4 ++-- exchanges/exchange_test.go | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/currency/manager.go b/currency/manager.go index cacf13cb..d7639f2c 100644 --- a/currency/manager.go +++ b/currency/manager.go @@ -189,7 +189,7 @@ func (p *PairsManager) GetFormat(a asset.Item, request bool) (PairFormat, error) pFmt = p.ConfigFormat } } else { - ps, err := p.Get(a) + ps, err := p.getPairStoreRequiresLock(a) if err != nil { return EMPTYFORMAT, err } @@ -471,7 +471,7 @@ func (p *PairsManager) getPairStoreRequiresLock(a asset.Item) (*PairStore, error pairStore, ok := p.Pairs[a] if !ok { - return nil, fmt.Errorf("%w %v", ErrAssetNotFound, a) + return nil, fmt.Errorf("%w %w %v", ErrAssetNotFound, asset.ErrNotSupported, a) } if pairStore == nil { diff --git a/exchanges/exchange_test.go b/exchanges/exchange_test.go index b6cd3d2c..5917eb9d 100644 --- a/exchanges/exchange_test.go +++ b/exchanges/exchange_test.go @@ -700,7 +700,13 @@ func TestGetFeatures(t *testing.T) { func TestGetPairFormat(t *testing.T) { t.Parallel() - _, err := new(Base).GetPairFormat(asset.Spot, true) + b := new(Base) + _, err := b.GetPairFormat(asset.Spot, true) + require.ErrorIs(t, err, currency.ErrPairManagerNotInitialised) + b.CurrencyPairs = currency.PairsManager{ + Pairs: make(currency.FullStore), + } + _, err = b.GetPairFormat(asset.Spot, true) require.ErrorIs(t, err, asset.ErrNotSupported, "Must delegate to GetFormat and error") }