Skip to content

Commit

Permalink
return error on merge with no profiles; (#330)
Browse files Browse the repository at this point in the history
defer channel close to prevent leaking channel
  • Loading branch information
thorfour authored Oct 19, 2021
1 parent c267b95 commit 3694d94
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions pkg/storage/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package storage
import (
"context"
"errors"
"fmt"
"runtime"

"go.opentelemetry.io/otel/attribute"
Expand Down Expand Up @@ -65,15 +66,16 @@ func MergeSeriesSetProfiles(tracer trace.Tracer, ctx context.Context, set Series
func() error {
_, seriesSpan := tracer.Start(ctx, "seriesIterate")
defer seriesSpan.End()
defer close(profileCh)
for {
select {
case <-ctx.Done():
break
return ctx.Err()
default:
}

if !set.Next() {
break
return nil
}
series := set.At()

Expand All @@ -92,8 +94,6 @@ func MergeSeriesSetProfiles(tracer trace.Tracer, ctx context.Context, set Series
return err
}
}
close(profileCh)
return nil
},
)
}
Expand Down Expand Up @@ -220,6 +220,10 @@ func MergeProfilesConcurrent(
return nil, err
}

if res == nil {
return nil, fmt.Errorf("no profiles to merge")
}

return res, nil
}

Expand Down

0 comments on commit 3694d94

Please sign in to comment.