Skip to content

Commit

Permalink
[extension/jaegerremotesampling] fix: wait for autoUpdateStrategies i…
Browse files Browse the repository at this point in the history
…n Close function (open-telemetry#37289)

#### Description
Add a waitGroup to strategyProvider struct that waits for
autoUpdateStrategies in the Close function

#### Link to tracking issue
Fixes open-telemetry#37275

---------

Signed-off-by: Aryan Goyal <[email protected]>
Co-authored-by: Yuri Shkuro <[email protected]>
  • Loading branch information
2 people authored and chengchuanpeng committed Jan 26, 2025
1 parent 29dd954 commit 2a47c0f
Showing 1 changed file with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"net/url"
"os"
"path/filepath"
"sync"
"sync/atomic"
"time"

Expand All @@ -34,6 +35,8 @@ type samplingProvider struct {
cancelFunc context.CancelFunc

options Options

wg sync.WaitGroup
}

type storedStrategies struct {
Expand Down Expand Up @@ -77,6 +80,7 @@ func NewFileSource(options Options, logger *zap.Logger) (source.Source, error) {
}

if options.ReloadInterval > 0 {
h.wg.Add(1)
go h.autoUpdateStrategies(ctx, options.ReloadInterval, loadFn)
}
return h, nil
Expand All @@ -96,6 +100,7 @@ func (h *samplingProvider) GetSamplingStrategy(_ context.Context, serviceName st
// Close stops updating the strategies
func (h *samplingProvider) Close() error {
h.cancelFunc()
h.wg.Wait()
return nil
}

Expand Down Expand Up @@ -156,6 +161,7 @@ func (h *samplingProvider) samplingStrategyLoader(strategiesFile string) strateg
}

func (h *samplingProvider) autoUpdateStrategies(ctx context.Context, interval time.Duration, loader strategyLoader) {
defer h.wg.Done()
lastValue := string(nullJSON)
ticker := time.NewTicker(interval)
defer ticker.Stop()
Expand Down

0 comments on commit 2a47c0f

Please sign in to comment.