From 36f8d1dcff27629ce9f809936b477942d5b89d53 Mon Sep 17 00:00:00 2001 From: nick Date: Fri, 23 Aug 2024 13:09:12 +0900 Subject: [PATCH] fix: update based on feedbacks --- node/cmd/node/main.go | 5 +++++ node/pkg/checker/ping/app.go | 5 ----- node/pkg/checker/ping/app_test.go | 7 ------- 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/node/cmd/node/main.go b/node/cmd/node/main.go index aa8cbf497..d6c65961e 100644 --- a/node/cmd/node/main.go +++ b/node/cmd/node/main.go @@ -22,6 +22,11 @@ func main() { ctx := context.Background() go func() { + defer func() { + if r := recover(); r != nil { + log.Error().Any("panic", r).Msg("panic recovered from network checks") + } + }() time.Sleep(5 * time.Second) // give some buffer until the app is ready ping.Run(ctx) os.Exit(1) diff --git a/node/pkg/checker/ping/app.go b/node/pkg/checker/ping/app.go index 1d34b778a..a352d26cb 100644 --- a/node/pkg/checker/ping/app.go +++ b/node/pkg/checker/ping/app.go @@ -2,7 +2,6 @@ package ping import ( "context" - "sync" "time" probing "github.com/prometheus-community/pro-bing" @@ -70,7 +69,6 @@ type App struct { Endpoints []PingEndpoint FailCount map[string]int ResultsBuffer chan PingResult - mu sync.Mutex } func (pe *PingEndpoint) run() error { @@ -157,7 +155,6 @@ func (app *App) Start(ctx context.Context) { case <-ctx.Done(): return case result := <-app.ResultsBuffer: - app.mu.Lock() if result.Success && result.Delay < app.MaxDelay { app.FailCount[result.Address] = 0 } else { @@ -174,10 +171,8 @@ func (app *App) Start(ctx context.Context) { // shuts down if all endpoints fails pinging 2 times in a row if failedCount == len(app.Endpoints) { log.Error().Msg("All pings failed, shutting down") - app.mu.Unlock() return } - app.mu.Unlock() } } diff --git a/node/pkg/checker/ping/app_test.go b/node/pkg/checker/ping/app_test.go index a84dab71e..600d55e3d 100644 --- a/node/pkg/checker/ping/app_test.go +++ b/node/pkg/checker/ping/app_test.go @@ -47,8 +47,6 @@ func TestApp_Start_SuccessfulPing(t *testing.T) { app.Start(ctx) - app.mu.Lock() - defer app.mu.Unlock() assert.Equal(t, 0, app.FailCount["8.8.8.8"]) } @@ -69,8 +67,6 @@ func TestApp_Start_FailedPing(t *testing.T) { app.Start(ctx) // Ensure FailCount incremented due to failure - app.mu.Lock() - defer app.mu.Unlock() assert.Equal(t, 1, app.FailCount["8.8.8.8"]) } @@ -92,9 +88,6 @@ func TestApp_Start_ShutdownOnAllFailures(t *testing.T) { app.Start(ctx) - app.mu.Lock() - defer app.mu.Unlock() - // Check that FailCount for all endpoints has reached DefaultMaxFails for _, endpoint := range app.Endpoints { assert.Equal(t, DefaultMaxFails, app.FailCount[endpoint.Address])