From 5724ff8aa66acffbcd560cb262dcde456abc5a35 Mon Sep 17 00:00:00 2001 From: TrooperCrypto Date: Wed, 21 May 2025 12:58:46 +0200 Subject: [PATCH 1/2] add dialWithTimeout When establishing connections this avoids having the function stuck trying to connect to the clients --- shared/services/ec-manager.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/shared/services/ec-manager.go b/shared/services/ec-manager.go index be358eb1b..a4e186415 100644 --- a/shared/services/ec-manager.go +++ b/shared/services/ec-manager.go @@ -64,14 +64,14 @@ func NewExecutionClientManager(cfg *config.RocketPoolConfig) (*ExecutionClientMa } } - primaryEc, err := ethclient.Dial(primaryEcUrl) + primaryEc, err := dialWithTimeout(primaryEcUrl) if err != nil { return nil, fmt.Errorf("error connecting to primary EC at [%s]: %w", primaryEcUrl, err) } var fallbackEc *ethclient.Client if fallbackEcUrl != "" { - fallbackEc, err = ethclient.Dial(fallbackEcUrl) + fallbackEc, err = dialWithTimeout(fallbackEcUrl) if err != nil { return nil, fmt.Errorf("error connecting to fallback EC at [%s]: %w", fallbackEcUrl, err) } @@ -89,6 +89,12 @@ func NewExecutionClientManager(cfg *config.RocketPoolConfig) (*ExecutionClientMa } +func dialWithTimeout(url string) (*ethclient.Client, error) { + initalConnectionCtx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + defer cancel() + return ethclient.DialContext(initalConnectionCtx, url) +} + /// ======================== /// ContractCaller Functions /// ======================== From 105582e8fdc49555a54f81904c4c308fd911ffe4 Mon Sep 17 00:00:00 2001 From: Fornax <23104993+0xfornax@users.noreply.github.com> Date: Thu, 22 May 2025 13:34:08 -0300 Subject: [PATCH 2/2] Fix lint --- shared/services/ec-manager.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared/services/ec-manager.go b/shared/services/ec-manager.go index a4e186415..91f498ce8 100644 --- a/shared/services/ec-manager.go +++ b/shared/services/ec-manager.go @@ -89,7 +89,7 @@ func NewExecutionClientManager(cfg *config.RocketPoolConfig) (*ExecutionClientMa } -func dialWithTimeout(url string) (*ethclient.Client, error) { +func dialWithTimeout(url string) (*ethclient.Client, error) { initalConnectionCtx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() return ethclient.DialContext(initalConnectionCtx, url)