From f4c226c7d5069e21d72682e88855e2043ed8fcb4 Mon Sep 17 00:00:00 2001 From: Frederic Branczyk Date: Thu, 23 Nov 2017 11:45:00 +0100 Subject: [PATCH] inhibit: Fix race in stopping inhibitor --- inhibit/inhibit.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/inhibit/inhibit.go b/inhibit/inhibit.go index 1d4834fa..b1c61920 100644 --- a/inhibit/inhibit.go +++ b/inhibit/inhibit.go @@ -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() }