Merge pull request #1527 from prometheus/fabxc/fixrace

Fix potential race in ctx intialization
This commit is contained in:
Fabian Reinartz 2016-04-05 22:41:01 +02:00
commit da701f9d13
2 changed files with 8 additions and 1 deletions

View file

@ -130,6 +130,13 @@ func newScrapePool(cfg *config.ScrapeConfig, app storage.SampleAppender) *scrape
}
}
func (sp *scrapePool) init(ctx context.Context) {
sp.mtx.Lock()
defer sp.mtx.Unlock()
sp.ctx = ctx
}
// stop terminates all scrape loops and returns after they all terminated.
func (sp *scrapePool) stop() {
var wg sync.WaitGroup

View file

@ -224,7 +224,7 @@ func (ts *targetSet) reload(cfg *config.ScrapeConfig) {
func (ts *targetSet) runScraping(ctx context.Context) {
ctx, ts.cancelScraping = context.WithCancel(ctx)
ts.scrapePool.ctx = ctx
ts.scrapePool.init(ctx)
Loop:
for {