Fix datarace in node ping controller

This commit is contained in:
Sargun Dhillon
2020-09-21 22:22:22 -07:00
parent 4b74a01f8f
commit cf2d5264a5

View File

@@ -19,7 +19,7 @@ type nodePingController struct {
// "Results" // "Results"
sync.Mutex sync.Mutex
result pingResult result *pingResult
} }
type pingResult struct { type pingResult struct {
@@ -88,8 +88,8 @@ func (npc *nodePingController) run(ctx context.Context) {
} }
npc.Lock() npc.Lock()
npc.result = pingResult
defer npc.Unlock() defer npc.Unlock()
npc.result = &pingResult
span.SetStatus(pingResult.error) span.SetStatus(pingResult.error)
} }
@@ -108,5 +108,7 @@ func (npc *nodePingController) getResult(ctx context.Context) (*pingResult, erro
case <-npc.firstPingCompleted: case <-npc.firstPingCompleted:
} }
return &npc.result, nil npc.Lock()
defer npc.Unlock()
return npc.result, nil
} }