Skip to content

Commit

Permalink
Hotfix: race condition due to variable shadowing (#224)
Browse files Browse the repository at this point in the history
fix: race condition due to variable shadowing

Signed-off-by: Niklas Treml <[email protected]>
  • Loading branch information
niklastreml authored Nov 18, 2024
1 parent b9e9a80 commit f79499f
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions pkg/checks/traceroute/traceroute.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,19 +195,19 @@ 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()

l := log.With("ttl", ttl)
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++
}()
Expand All @@ -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
Expand Down

0 comments on commit f79499f

Please sign in to comment.