From da40aceed92dc283c5949c95370a75927b246b91 Mon Sep 17 00:00:00 2001 From: Niklas Treml Date: Mon, 18 Nov 2024 15:22:55 +0100 Subject: [PATCH] fix: race condition due to variable shadowing Signed-off-by: Niklas Treml --- pkg/checks/traceroute/traceroute.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pkg/checks/traceroute/traceroute.go b/pkg/checks/traceroute/traceroute.go index 338ab8c6..7a2314f1 100644 --- a/pkg/checks/traceroute/traceroute.go +++ b/pkg/checks/traceroute/traceroute.go @@ -195,11 +195,11 @@ func TraceRoute(ctx context.Context, cfg tracerouteConfig) (map[int][]Hop, error var wg sync.WaitGroup for ttl := 1; ttl <= cfg.MaxHops; ttl++ { - c, hopSpan := tracer.Start(ctx, addr.String(), trace.WithAttributes( - attribute.Int("ttl", ttl), - )) wg.Add(1) go func(ttl int) { + c, hopSpan := tracer.Start(ctx, addr.String(), trace.WithAttributes( + attribute.Int("ttl", ttl), + )) defer wg.Done() defer hopSpan.End() @@ -207,7 +207,7 @@ func TraceRoute(ctx context.Context, cfg tracerouteConfig) (map[int][]Hop, error logctx := logger.IntoContext(c, l) retry := 0 - err = helper.Retry(func(ctx context.Context) error { + retryErr := helper.Retry(func(ctx context.Context) error { defer func() { retry++ }() @@ -234,10 +234,10 @@ func TraceRoute(ctx context.Context, cfg tracerouteConfig) (map[int][]Hop, error } return nil }, cfg.Rc)(logctx) - if err != nil { + if retryErr != nil { l.DebugContext(ctx, "Traceroute could not reach target") if !errors.Is(err, syscall.EHOSTUNREACH) { - hopSpan.SetStatus(codes.Error, err.Error()) + hopSpan.SetStatus(codes.Error, retryErr.Error()) hopSpan.RecordError(err) } return