From bf40e0a6ebe2031a94e9df32b24dbafcfee97dca Mon Sep 17 00:00:00 2001 From: dwasse Date: Wed, 7 Aug 2024 08:28:18 -0500 Subject: [PATCH] Fix: misc context leaks (#2984) --- services/rfq/relayer/inventory/manager.go | 2 +- services/rfq/relayer/pricer/fee_pricer.go | 19 ++++++++----------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/services/rfq/relayer/inventory/manager.go b/services/rfq/relayer/inventory/manager.go index 44dee016ff..4778bf72a7 100644 --- a/services/rfq/relayer/inventory/manager.go +++ b/services/rfq/relayer/inventory/manager.go @@ -226,7 +226,7 @@ func NewInventoryManager(ctx context.Context, clientFetcher submitter.ClientFetc //nolint:gocognit,cyclop func (i *inventoryManagerImpl) Start(ctx context.Context) error { - g, _ := errgroup.WithContext(ctx) + g, ctx := errgroup.WithContext(ctx) for _, rebalanceManager := range i.rebalanceManagers { rebalanceManager := rebalanceManager g.Go(func() error { diff --git a/services/rfq/relayer/pricer/fee_pricer.go b/services/rfq/relayer/pricer/fee_pricer.go index d8e925aa0d..fce8e30982 100644 --- a/services/rfq/relayer/pricer/fee_pricer.go +++ b/services/rfq/relayer/pricer/fee_pricer.go @@ -13,7 +13,6 @@ import ( "github.com/synapsecns/sanguine/services/rfq/relayer/relconfig" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/trace" - "golang.org/x/sync/errgroup" ) // FeePricer is the interface for the fee pricer. @@ -66,17 +65,15 @@ func NewFeePricer(config relconfig.Config, clientFetcher submitter.ClientFetcher } func (f *feePricer) Start(ctx context.Context) { - g, _ := errgroup.WithContext(ctx) - // Start the TTL caches. - g.Go(func() error { - f.gasPriceCache.Start() - return nil - }) - g.Go(func() error { - f.tokenPriceCache.Start() - return nil - }) + go f.gasPriceCache.Start() + go f.tokenPriceCache.Start() + + go func() { + <-ctx.Done() + f.gasPriceCache.Stop() + f.tokenPriceCache.Stop() + }() } var nativeDecimalsFactor = new(big.Int).Exp(big.NewInt(10), big.NewInt(int64(18)), nil)