Skip to content

Commit

Permalink
Fix logging data race
Browse files Browse the repository at this point in the history
  • Loading branch information
yinyic committed Aug 28, 2022
1 parent 03d0b8a commit a060984
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions agent/ecscni/plugin_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ func (client *cniClient) setupNS(ctx context.Context, cfg *Config) (*current.Res
cfg.ContainerID)
}

seelog.Debugf("[ECSCNI] Completed setting up the container namespace: %v", bridgeResult)
// Use fmt.Sprintf to force a synchrounous read of 'bridgeResult'. If we use seelog.Debugf("...%v", bridgeResult)
// seelog asynchronously reads/evaluates bridgeResult, and could cause data race because there's an immediate
// write on bridgeResult (from bridgeResult.GetAsVersion())
seelog.Debugf("[ECSCNI] Completed setting up the container namespace: %s", fmt.Sprintf("%v", bridgeResult))

if _, err := bridgeResult.GetAsVersion(currentCNISpec); err != nil {
seelog.Warnf("[ECSCNI] Unable to convert result to spec version %s; error: %v; result is of version: %s",
Expand All @@ -89,7 +92,8 @@ func (client *cniClient) setupNS(ctx context.Context, cfg *Config) (*current.Res
curResult, ok := bridgeResult.(*current.Result)
if !ok {
return nil, errors.Errorf(
"cni setup: unable to convert result to expected version '%v'", bridgeResult)
"cni setup: unable to convert result to expected version '%s'",
fmt.Sprintf("%v", bridgeResult))
}

return curResult, nil
Expand Down

0 comments on commit a060984

Please sign in to comment.