Skip to content

Commit

Permalink
Cleanup execs and fix Range() iteration
Browse files Browse the repository at this point in the history
  * Clean the execs map in hcsTask after init exits
  * Fix the Range() iteration in hcsTask

Signed-off-by: Gabriel Adrian Samfira <[email protected]>
  • Loading branch information
gabriel-samfira committed Dec 27, 2021
1 parent 2ef15cd commit 2d07914
Show file tree
Hide file tree
Showing 2 changed files with 28 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
33 changes: 25 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,8 @@ func (ht *hcsTask) DeleteExec(ctx context.Context, eid string) (int, uint32, tim
ex.ForceExit(ctx, 1)
}

// iterate next. Returning false here, means only sending
// Kill to the first task in the map.
// Iterate all. Returning false stops the iteration. See:
// https://pkg.go.dev/sync#Map.Range
return true
})
}
Expand Down Expand Up @@ -608,6 +609,20 @@ func (ht *hcsTask) DeleteExec(ctx context.Context, eid string) (int, uint32, tim
return 0, 0, time.Time{}, errors.Wrap(hcs.ErrTimeout, "waiting for container resource cleanup")
case <-ht.closed:
}

// The init task has now exited. A ForceExit() has already been sent to
// execs. Cleanup execs and continue.
ht.execs.Range(func(key, value interface{}) bool {
if key == "" {
// Iterate next.
return true
}
ht.execs.Delete(key)

// Iterate all. Returning false stops the iteration. See:
// https://pkg.go.dev/sync#Map.Range
return true
})
}

status := e.Status()
Expand Down Expand Up @@ -639,8 +654,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 @@ -721,8 +737,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 2d07914

Please sign in to comment.