diff --git a/bridge/cmd/guardiand/processor.go b/bridge/cmd/guardiand/processor.go index 26f8a267e..d9cf18a94 100644 --- a/bridge/cmd/guardiand/processor.go +++ b/bridge/cmd/guardiand/processor.go @@ -66,7 +66,8 @@ func vaaConsensusProcessor(lockC chan *common.ChainLock, setC chan *common.Guard len(gs.Keys), *devNumGuardians), zap.Any("v", v)) - timeout, _ := context.WithTimeout(ctx, 15*time.Second) + timeout, cancel := context.WithTimeout(ctx, 15*time.Second) + defer cancel() tx, err := devnet.SubmitVAA(timeout, *ethRPC, v) if err != nil { logger.Error("failed to submit devnet guardian set change", zap.Error(err)) @@ -277,10 +278,12 @@ func vaaConsensusProcessor(lockC chan *common.ChainLock, setC chan *common.Guard vaaC <- state.vaaSignatures[hash].ourVAA } case t.TargetChain == vaa.ChainIDEthereum: - timeout, _ := context.WithTimeout(ctx, 15*time.Second) + timeout, cancel := context.WithTimeout(ctx, 15*time.Second) tx, err := devnet.SubmitVAA(timeout, *ethRPC, v) + cancel() if err != nil { logger.Error("failed to submit lockup to Ethereum", zap.Error(err)) + break } logger.Info("lockup submitted to Ethereum", zap.Any("tx", tx)) default: diff --git a/bridge/pkg/ethereum/watcher.go b/bridge/pkg/ethereum/watcher.go index 1480014e5..839f7f420 100644 --- a/bridge/pkg/ethereum/watcher.go +++ b/bridge/pkg/ethereum/watcher.go @@ -43,7 +43,8 @@ func NewEthBridgeWatcher(url string, bridge eth_common.Address, minConfirmations } func (e *EthBridgeWatcher) Run(ctx context.Context) error { - timeout, _ := context.WithTimeout(ctx, 15*time.Second) + timeout, cancel := context.WithTimeout(ctx, 15*time.Second) + defer cancel() c, err := ethclient.DialContext(timeout, e.url) if err != nil { return fmt.Errorf("dialing eth client failed: %w", err) @@ -60,7 +61,8 @@ func (e *EthBridgeWatcher) Run(ctx context.Context) error { } // Timeout for initializing subscriptions - timeout, _ = context.WithTimeout(ctx, 15*time.Second) + timeout, cancel = context.WithTimeout(ctx, 15*time.Second) + defer cancel() // Subscribe to new token lockups tokensLockedC := make(chan *abi.AbiLogTokensLocked, 2) @@ -94,8 +96,9 @@ func (e *EthBridgeWatcher) Run(ctx context.Context) error { return case ev := <-tokensLockedC: // Request timestamp for block - timeout, _ = context.WithTimeout(ctx, 15*time.Second) + timeout, cancel = context.WithTimeout(ctx, 15*time.Second) b, err := c.BlockByNumber(timeout, big.NewInt(int64(ev.Raw.BlockNumber))) + cancel() if err != nil { errC <- fmt.Errorf("failed to request timestamp for block %d: %w", ev.Raw.BlockNumber, err) return @@ -192,7 +195,8 @@ func (e *EthBridgeWatcher) Run(ctx context.Context) error { supervisor.Signal(ctx, supervisor.SignalHealthy) // Fetch current guardian set - timeout, _ = context.WithTimeout(ctx, 15*time.Second) + timeout, cancel = context.WithTimeout(ctx, 15*time.Second) + defer cancel() opts := &bind.CallOpts{Context: timeout} currentIndex, err := caller.GuardianSetIndex(opts) diff --git a/bridge/pkg/solana/watcher.go b/bridge/pkg/solana/watcher.go index a16034ccb..102cc3b48 100644 --- a/bridge/pkg/solana/watcher.go +++ b/bridge/pkg/solana/watcher.go @@ -43,7 +43,8 @@ func padAddress(address eth_common.Address) vaa.Address { } func (e *SolanaBridgeWatcher) Run(ctx context.Context) error { - timeout, _ := context.WithTimeout(ctx, 15*time.Second) + timeout, cancel := context.WithTimeout(ctx, 15*time.Second) + defer cancel() conn, err := grpc.DialContext(timeout, e.url, grpc.WithBlock(), grpc.WithInsecure()) if err != nil { return fmt.Errorf("failed to dial agent at %s: %w", e.url, err) @@ -113,8 +114,9 @@ func (e *SolanaBridgeWatcher) Run(ctx context.Context) error { } h := hex.EncodeToString(m.Bytes()) - timeout, _ := context.WithTimeout(ctx, 15*time.Second) + timeout, cancel := context.WithTimeout(ctx, 15*time.Second) res, err := c.SubmitVAA(timeout, &agentv1.SubmitVAARequest{Vaa: vaaBytes}) + cancel() if err != nil { logger.Error("failed to submit VAA", zap.Error(err), zap.String("digest", h)) break