Skip to content

Commit

Permalink
Fix Range() iteration
Browse files Browse the repository at this point in the history
The function passed into the Range function of sync.Map will stop the
iteration if false is returned. This commit makes sure we iterate
through all elements in the map.

Signed-off-by: Gabriel Adrian Samfira <[email protected]>
  • Loading branch information
gabriel-samfira committed Jan 6, 2022
1 parent e093fbd commit 76881a2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
5 changes: 3 additions & 2 deletions cmd/containerd-shim-runhcs-v1/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,9 @@ func (p *pod) KillTask(ctx context.Context, tid, eid string, signal uint32, all
return wt.KillExec(ctx, eid, signal, all)
})

// iterate all
return false
// Iterate all. Returning false stops the iteration. See:
// https://pkg.go.dev/sync#Map.Range
return true
})
}
eg.Go(func() error {
Expand Down
20 changes: 12 additions & 8 deletions cmd/containerd-shim-runhcs-v1/task_hcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -536,8 +536,9 @@ func (ht *hcsTask) KillExec(ctx context.Context, eid string, signal uint32, all
}).Warn("failed to kill exec in task")
}

// iterate all
return false
// Iterate all. Returning false stops the iteration. See:
// https://pkg.go.dev/sync#Map.Range
return true
})
}
if signal == 0x9 && eid == "" && ht.host != nil {
Expand Down Expand Up @@ -578,8 +579,9 @@ func (ht *hcsTask) DeleteExec(ctx context.Context, eid string) (int, uint32, tim
ex.ForceExit(ctx, 1)
}

// iterate next
return false
// Iterate all. Returning false stops the iteration. See:
// https://pkg.go.dev/sync#Map.Range
return true
})
}
switch state := e.State(); state {
Expand Down Expand Up @@ -617,8 +619,9 @@ func (ht *hcsTask) Pids(ctx context.Context) ([]runhcsopts.ProcessDetails, error
ex := value.(shimExec)
pidMap[ex.Pid()] = ex.ID()

// Iterate all
return false
// Iterate all. Returning false stops the iteration. See:
// https://pkg.go.dev/sync#Map.Range
return true
})
pidMap[ht.init.Pid()] = ht.init.ID()

Expand Down Expand Up @@ -699,8 +702,9 @@ func (ht *hcsTask) waitForHostExit() {
ex := value.(shimExec)
ex.ForceExit(ctx, 1)

// iterate all
return false
// Iterate all. Returning false stops the iteration. See:
// https://pkg.go.dev/sync#Map.Range
return true
})
ht.init.ForceExit(ctx, 1)
ht.closeHost(ctx)
Expand Down

0 comments on commit 76881a2

Please sign in to comment.