inhibit: Fix race in stopping inhibitor

This commit is contained in:
Frederic Branczyk 2017-11-23 11:45:00 +01:00
parent 55a40d1d3a
commit f4c226c7d5
No known key found for this signature in database
GPG Key ID: 7741A52782A90069
1 changed files with 4 additions and 0 deletions

View File

@ -103,7 +103,9 @@ func (ih *Inhibitor) Run() {
ctx context.Context
)
ih.mtx.Lock()
ctx, ih.cancel = context.WithCancel(context.Background())
ih.mtx.Unlock()
gcCtx, gcCancel := context.WithCancel(ctx)
runCtx, runCancel := context.WithCancel(ctx)
@ -129,6 +131,8 @@ func (ih *Inhibitor) Stop() {
return
}
ih.mtx.RLock()
defer ih.mtx.RUnlock()
if ih.cancel != nil {
ih.cancel()
}