From 91fd5b3c91e9af845dfa4e111741dd6c4b27065c Mon Sep 17 00:00:00 2001 From: Peter Kieltyka Date: Thu, 4 Apr 2024 14:42:16 -0400 Subject: [PATCH] ethmonitor: add network timeout when fetching chainId --- ethmonitor/ethmonitor.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ethmonitor/ethmonitor.go b/ethmonitor/ethmonitor.go index c3f78867..ebd75be5 100644 --- a/ethmonitor/ethmonitor.go +++ b/ethmonitor/ethmonitor.go @@ -1025,16 +1025,21 @@ func (m *Monitor) setPayload(value []byte) []byte { func getChainID(provider ethrpc.Interface) (*big.Int, error) { var chainID *big.Int err := breaker.Do(context.Background(), func() error { - id, err := provider.ChainID(context.Background()) + ctx, cancel := context.WithTimeout(context.Background(), 4*time.Second) + defer cancel() + + id, err := provider.ChainID(ctx) if err != nil { return err } chainID = id return nil - }, nil, 1*time.Second, 2, 20) + }, nil, 1*time.Second, 2, 3) + if err != nil { return nil, err } + return chainID, nil }