Skip to content

Commit

Permalink
Delete the task object and fixes
Browse files Browse the repository at this point in the history
  * After successfully deleting the init task exec, clear the
taskOrPod atomic value.
  * Fix the function return for ht.execs.Range(). The function returned
false, which would stop the iteration after the first element in the
map.

Signed-off-by: Gabriel Adrian Samfira <[email protected]>
  • Loading branch information
gabriel-samfira committed Dec 23, 2021
1 parent 2ef15cd commit 57417fb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
10 changes: 9 additions & 1 deletion cmd/containerd-shim-runhcs-v1/service_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"
"path/filepath"
"strings"
"sync/atomic"

runhcsopts "github.com/Microsoft/hcsshim/cmd/containerd-shim-runhcs-v1/options"
"github.com/Microsoft/hcsshim/internal/oci"
Expand Down Expand Up @@ -215,7 +216,14 @@ func (s *service) deleteInternal(ctx context.Context, req *task.DeleteRequest) (
if err != nil {
return nil, err
}
// TODO: We should be removing the task after this right?

if req.ExecID == "" {
// We've successfully deleted the init exec. Compute resources
// should be closed, layers umounted and resources released.
// This task should now be done.
s.taskOrPod = atomic.Value{}
}

return &task.DeleteResponse{
Pid: uint32(pid),
ExitStatus: exitStatus,
Expand Down
19 changes: 11 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 @@ -639,8 +640,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 +723,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 57417fb

Please sign in to comment.