Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -602,8 +602,8 @@ jobs:
sudo BOX=$BOX RUNC_FLAVOR=$RUNC_FLAVOR vagrant halt
sudo BOX=$BOX RUNC_FLAVOR=$RUNC_FLAVOR vagrant up
fi
- name: test-integration
run: sudo BOX=$BOX RUNC_FLAVOR=$RUNC_FLAVOR vagrant up --provision-with=selinux,install-runc,install-gotestsum,test-integration
# - name: test-integration
# run: sudo BOX=$BOX RUNC_FLAVOR=$RUNC_FLAVOR vagrant up --provision-with=selinux,install-runc,install-gotestsum,test-integration
- name: test-cri-integration
run: sudo BOX=$BOX CGROUP_DRIVER=$CGROUP_DRIVER RUNC_FLAVOR=$RUNC_FLAVOR vagrant up --provision-with=selinux,install-runc,install-gotestsum,test-cri-integration
- name: test-cri
Expand Down
16 changes: 16 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "debug",
"type": "go",
"request": "launch",
"mode": "auto",
"env": {"GO111MODULE":"on"},
"program": "${workspaceFolder}/cmd/containerd"
}
]
}
1 change: 1 addition & 0 deletions client/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ func (p *process) Wait(ctx context.Context) (<-chan ExitStatus, error) {
ContainerID: p.task.id,
ExecID: p.id,
})

if err != nil {
c <- ExitStatus{
code: UnknownExitStatus,
Expand Down
5 changes: 5 additions & 0 deletions cmd/containerd-shim-runc-v2/task/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ func (s *service) preStart(c *runc.Container) (handleStarted func(*runc.Containe
s.lifecycleMu.Unlock()
for _, ee := range ees {
s.handleProcessExit(ee, c, p)
log.G(context.Background()).Infof("nmx001 e is %v", ee)
}
} else {
// Process start was successful, add to `s.running`.
Expand Down Expand Up @@ -686,8 +687,10 @@ func (s *service) processExits() {
for _, cp := range cps {
if ip, ok := cp.Process.(*process.Init); ok {
s.handleInitExit(e, cp.Container, ip)
log.G(context.Background()).Infof("nmx002 e is %v", e)
} else {
s.handleProcessExit(e, cp.Container, cp.Process)
log.G(context.Background()).Infof("nmx003 e is %v", e)
}
}
}
Expand Down Expand Up @@ -720,6 +723,7 @@ func (s *service) handleInitExit(e runcC.Exit, c *runc.Container, p *process.Ini
if numRunningExecs == 0 {
delete(s.runningExecs, c)
s.lifecycleMu.Unlock()
log.G(context.Background()).Infof("nmx004 e is %v", e)
s.handleProcessExit(e, c, p)
return
}
Expand All @@ -746,6 +750,7 @@ func (s *service) handleInitExit(e runcC.Exit, c *runc.Container, p *process.Ini

// all running processes have exited now, and no new
// ones can start, so we can publish the init exit
log.G(context.Background()).Infof("nmx005 e is %v", e)
s.handleProcessExit(e, c, p)
}()
}
Expand Down
10 changes: 8 additions & 2 deletions core/runtime/v2/shim.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"net"
"os"
"path/filepath"
goruntime "runtime"
"strings"
"time"

Expand Down Expand Up @@ -134,11 +135,16 @@ func loadShim(ctx context.Context, bundle *Bundle, onClose func()) (_ ShimInstan
return shim, nil
}

func stack() string {
var buf [2 << 10]byte
return string(buf[:goruntime.Stack(buf[:], true)])
}

func cleanupAfterDeadShim(ctx context.Context, id string, rt *runtime.NSMap[ShimInstance], events *exchange.Exchange, binaryCall *binary) {
ctx, cancel := timeout.WithContext(ctx, cleanupTimeout)
defer cancel()

log.G(ctx).WithField("id", id).Info("cleaning up after shim disconnected")
log.G(ctx).Infof("nmx666 %s", stack())
log.G(ctx).WithField("id", id).Info("cleaning up after shim disconnected001")
response, err := binaryCall.Delete(ctx)
if err != nil {
log.G(ctx).WithError(err).WithField("id", id).Warn("failed to clean up after shim disconnected")
Expand Down
2 changes: 1 addition & 1 deletion core/runtime/v2/shim_load.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func (m *ShimManager) loadShim(ctx context.Context, bundle *Bundle) error {
})
// TODO: It seems we can only call loadShim here if it is a sandbox shim?
shim, err := loadShimTask(ctx, bundle, func() {
log.G(ctx).WithField("id", id).Info("shim disconnected")
log.G(ctx).WithField("id", id).Info("shim disconnected when loadShimTask")

cleanupAfterDeadShim(context.WithoutCancel(ctx), id, m.shims, m.events, binaryCall)
// Remove self from the runtime task list.
Expand Down
7 changes: 6 additions & 1 deletion core/runtime/v2/shim_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,11 @@ func (m *ShimManager) Start(ctx context.Context, id string, bundle *Bundle, opts
return nil, fmt.Errorf("failed to write bootstrap.json for bundle %s: %w", bundle.Path, err)
}

// onCloseWithShimLog := func() {
// onClose()
// cancelShimLog()
// f.Close()
// }
shim, err := loadShim(ctx, bundle, func() {})
if err != nil {
return nil, fmt.Errorf("failed to load sandbox task %q: %w", opts.SandboxID, err)
Expand Down Expand Up @@ -287,7 +292,7 @@ func (m *ShimManager) startShim(ctx context.Context, bundle *Bundle, id string,
env: m.env,
})
shim, err := b.Start(ctx, typeurl.MarshalProto(topts), func() {
log.G(ctx).WithField("id", id).Info("shim disconnected")
log.G(ctx).WithField("id", id).Info("shim disconnected in startShim")

cleanupAfterDeadShim(context.WithoutCancel(ctx), id, m.shims, m.events, b)
// Remove self from the runtime task list. Even though the cleanupAfterDeadShim()
Expand Down
13 changes: 10 additions & 3 deletions integration/client/container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1927,6 +1927,7 @@ func TestContainerExecLargeOutputWithTTY(t *testing.T) {
if err != nil {
t.Fatal(err)
}
t.Logf("container id is %s TestContainerExecLargeOutputWithTTY", container.ID())
defer container.Delete(ctx, WithSnapshotCleanup)

task, err := container.NewTask(ctx, empty())
Expand All @@ -1944,7 +1945,8 @@ func TestContainerExecLargeOutputWithTTY(t *testing.T) {
t.Fatal(err)
}

for i := 0; i < 100; i++ {
for i := 0; i < 600; i++ {
t.Logf("test for %d times", i)
spec, err := container.Spec(ctx)
if err != nil {
t.Fatal(err)
Expand All @@ -1969,7 +1971,7 @@ func TestContainerExecLargeOutputWithTTY(t *testing.T) {
if err := process.Start(ctx); err != nil {
t.Fatal(err)
}

t.Logf("processPid %d", process.Pid())
// wait for the exec to return
status := <-processStatusC
code, _, err := status.Result()
Expand All @@ -1986,8 +1988,13 @@ func TestContainerExecLargeOutputWithTTY(t *testing.T) {

const expectedSuffix = "999999 1000000"
stdoutString := stdout.String()
t.Logf("len (stdoutString) is %d", len(stdoutString))
if len(stdoutString) == 0 {
t.Fatal(fmt.Errorf("len (stdoutString) is 0"))
}
t.Logf("the last 100 characters of the output:\n\n %q", stdoutString[len(stdoutString)-100:])
if !strings.Contains(stdoutString, expectedSuffix) {
t.Fatalf("process output does not end with %q at iteration %d, here are the last 20 characters of the output:\n\n %q", expectedSuffix, i, stdoutString[len(stdoutString)-20:])
t.Fatalf("process output does not end with %q at iteration %d, here are the last 20 characters of the output:\n\n %q", expectedSuffix, i, stdoutString[len(stdoutString)-100:])
}

}
Expand Down
7 changes: 5 additions & 2 deletions integration/sandbox_run_rollback_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,16 @@ func TestRunPodSandboxWithShimDeleteFailure(t *testing.T) {
}

t.Log("Cleanup leaky sandbox")
t.Logf("Cleanup leaky sandbox %s", sb.Id)
err = runtimeService.RemovePodSandbox(sb.Id)
require.NoError(t, err)
}
}

t.Run("CleanupAfterRestart", testCase(true))
t.Run("JustCleanup", testCase(false))
for i := 0; i < 20; i++ {
t.Run("CleanupAfterRestart", testCase(true))
t.Run("JustCleanup", testCase(false))
}
}

// TestRunPodSandboxWithShimStartAndTeardownCNIFailure should keep the sandbox
Expand Down
1 change: 1 addition & 0 deletions internal/cri/server/events/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ func (em *EventMonitor) Start() <-chan error {
log.L.WithError(err).Errorf("Failed to convert event %+v", e)
break
}

if em.backOff.isInBackOff(id) {
log.L.Infof("Events for %q is in backoff, enqueue event %+v", id, evt)
em.backOff.enBackOff(id, evt)
Expand Down
7 changes: 6 additions & 1 deletion internal/cri/server/podsandbox/sandbox_stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package podsandbox

import (
"context"
"errors"
"fmt"
"syscall"
"time"
Expand Down Expand Up @@ -107,9 +108,13 @@ func (c *Controller) stopSandboxContainer(ctx context.Context, podSandbox *types
<-stopCh
}()
}

// Kill the pod sandbox container.
if err = task.Kill(ctx, syscall.SIGKILL); err != nil && !errdefs.IsNotFound(err) {
// shim is already exited
log.G(ctx).Warnf("task %s err is %v", task.ID(), err)
if errors.Is(err, errors.New("ttrpc: closed")) {
log.G(ctx).Warnf("task %s ", task.ID())
}
return fmt.Errorf("failed to kill pod sandbox container: %w", err)
}

Expand Down
11 changes: 9 additions & 2 deletions internal/cri/server/sandbox_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ func (c *criService) RunPodSandbox(ctx context.Context, r *runtime.RunPodSandbox
defer func() {
if retErr != nil && cleanupErr == nil {
cleanupErr = c.client.SandboxStore().Delete(ctx, id)
log.G(ctx).Infof("nmx6001 %s cleanupErr is %v", id, cleanupErr)
}
}()

Expand Down Expand Up @@ -214,7 +215,9 @@ func (c *criService) RunPodSandbox(ctx context.Context, r *runtime.RunPodSandbox
defer func() {
// Remove the network namespace only if all the resource cleanup is done
if retErr != nil && cleanupErr == nil {
if cleanupErr = sandbox.NetNS.Remove(); cleanupErr != nil {
cleanupErr = sandbox.NetNS.Remove()
log.G(ctx).Infof("nmx6002 %s cleanupErr is %v", id, cleanupErr)
if cleanupErr != nil {
log.G(ctx).WithError(cleanupErr).Errorf("Failed to remove network namespace %s for sandbox %q", sandbox.NetNSPath, id)
return
}
Expand All @@ -238,7 +241,10 @@ func (c *criService) RunPodSandbox(ctx context.Context, r *runtime.RunPodSandbox
deferCtx, deferCancel := util.DeferContext()
defer deferCancel()
// Teardown network if an error is returned.
if cleanupErr = c.teardownPodNetwork(deferCtx, sandbox); cleanupErr != nil {
cleanupErr = c.teardownPodNetwork(deferCtx, sandbox)
log.G(ctx).Infof("nmx6003 %s cleanupErr is %v", id, cleanupErr)
if cleanupErr != nil {
log.G(ctx).Infof("nmx6003 %s cleanupErr is %v", id, cleanupErr)
log.G(ctx).WithError(cleanupErr).Errorf("Failed to destroy network for sandbox %q", id)

// ignoring failed to destroy networks when we failed to setup networks
Expand Down Expand Up @@ -282,6 +288,7 @@ func (c *criService) RunPodSandbox(ctx context.Context, r *runtime.RunPodSandbox
var cerr podsandbox.CleanupErr
if errors.As(err, &cerr) {
cleanupErr = fmt.Errorf("failed to cleanup sandbox: %w", cerr)
log.G(ctx).Infof("nmx6004 %s cleanupErr is %v", id, cleanupErr)

// Strip last error as cleanup error to handle separately
if merr, ok := err.(interface{ Unwrap() []error }); ok {
Expand Down
Loading