From c19343727b3c1983d7b4286f22d5d4781d540c94 Mon Sep 17 00:00:00 2001 From: Andrew Davis <1709934+Savid@users.noreply.github.com> Date: Thu, 3 Jul 2025 14:02:02 +1000 Subject: [PATCH] fix: improve ClickHouse connection error handling in state manager MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Changed nil row responses to return errors instead of silently falling back to genesis block - Updated log levels from Warn to Error for ClickHouse connection failures - Added proper error logging for limiter client connection issues - Fixed inconsistent behavior where connection errors were treated as empty tables 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- pkg/state/manager.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/pkg/state/manager.go b/pkg/state/manager.go index ededf39..80a63b1 100644 --- a/pkg/state/manager.go +++ b/pkg/state/manager.go @@ -231,13 +231,13 @@ func (s *Manager) getProgressiveNextBlock(ctx context.Context, processor, networ row := s.storageClient.QueryRow(ctx, s.storageTable, query) if row == nil { - // ClickHouse client not started, return genesis block + // ClickHouse client not started - this is a connection error, not empty table s.log.WithFields(logrus.Fields{ "processor": processor, "network": network, - }).Warn("Storage ClickHouse client not available, starting from genesis block") + }).Error("Storage ClickHouse client not available") - return big.NewInt(0), nil + return nil, fmt.Errorf("storage ClickHouse client not available") } err := row.Scan(&blockNumber) @@ -296,11 +296,11 @@ func (s *Manager) getProgressiveNextBlockBackwards(ctx context.Context, processo row := s.storageClient.QueryRow(ctx, s.storageTable, query) if row == nil { - // ClickHouse client not started, need to find chain tip + // ClickHouse client not started - this is a connection error s.log.WithFields(logrus.Fields{ "processor": processor, "network": network, - }).Warn("Storage ClickHouse client not available for backwards mode") + }).Error("Storage ClickHouse client not available for backwards mode") return nil, fmt.Errorf("storage client not available for backwards processing") } @@ -369,6 +369,12 @@ func (s *Manager) getLimiterMaxBlock(ctx context.Context, network string) (*big. row := s.limiterClient.QueryRow(ctx, s.limiterTable, query) if row == nil { + // ClickHouse client not started - this is a connection error + s.log.WithFields(logrus.Fields{ + "network": network, + "table": s.limiterTable, + }).Error("Limiter ClickHouse client not available") + return nil, fmt.Errorf("limiter ClickHouse client not available") }