Skip to content

containerd restore container from checkpoint failed #4646

@Sampson2016

Description

@Sampson2016

Description

Steps to reproduce the issue:

  1. pull image: ctr -n demo i pull docker.io/library/redis:latest
  2. create container: ctr -n demo c create docker.io/library/redis:latest redis
  3. start container: ctr -n demo task start redis
  4. container checkpoint: ctr -n demo c checkpoint --rw --image --task redis redis-checkpoint
  5. container restore: ctr -n demo c restore --rw --live redis-checkpoint redis-checkpoint

Describe the results you received:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x555850ce0c04]

goroutine 1 [running]:
github.com/containerd/containerd/vendor/github.com/gogo/protobuf/types.(*Any).Reset(0x0)
        /home/runner/work/containerd/containerd/src/github.com/containerd/containerd/vendor/github.com/gogo/protobuf/types/any.pb.go:145 +0x24
github.com/containerd/containerd/vendor/github.com/gogo/protobuf/proto.Unmarshal(0xc0003a4420, 0x1c, 0x1c, 0x5558519073e0, 0x0, 0x45, 0xc0003ec050)
        /home/runner/work/containerd/containerd/src/github.com/containerd/containerd/vendor/github.com/gogo/protobuf/proto/decode.go:335 +0x3d
github.com/containerd/containerd.WithRestoreRuntime.func1(0x55585190c6e0, 0xc00034d200, 0xc00033c2a0, 0xc00032caa0, 0x0, 0x0)
        /home/runner/work/containerd/containerd/src/github.com/containerd/containerd/container_restore_opts.go:97 +0x291
github.com/containerd/containerd.(*Client).NewContainer(0xc00033c2a0, 0x55585190c6e0, 0xc00034d200, 0x7ffc8151a8ba, 0x10, 0xc000319840, 0x3, 0x4, 0x0, 0x0, ...)
        /home/runner/work/containerd/containerd/src/github.com/containerd/containerd/client.go:277 +0x1e9
github.com/containerd/containerd.(*Client).Restore(0xc00033c2a0, 0x55585190c6e0, 0xc00034d200, 0x7ffc8151a8ba, 0x10, 0x55585191b180, 0xc0003c2000, 0xc00020c758, 0x3, 0x3, ...)
        /home/runner/work/containerd/containerd/src/github.com/containerd/containerd/client.go:504 +0x3bd
github.com/containerd/containerd/cmd/ctr/commands/containers.glob..func7(0xc0000ed340, 0x0, 0x0)
        /home/runner/work/containerd/containerd/src/github.com/containerd/containerd/cmd/ctr/commands/containers/restore.go:79 +0x33f
github.com/containerd/containerd/vendor/github.com/urfave/cli.HandleAction(0x555851776b80, 0x5558518d88e0, 0xc0000ed340, 0xc0000ed340, 0x0)
        /home/runner/work/containerd/containerd/src/github.com/containerd/containerd/vendor/github.com/urfave/cli/app.go:523 +0xc0
github.com/containerd/containerd/vendor/github.com/urfave/cli.Command.Run(0x555851254127, 0x7, 0x0, 0x0, 0x0, 0x0, 0x0, 0x5558512702e3, 0x23, 0x0, ...)
        /home/runner/work/containerd/containerd/src/github.com/containerd/containerd/vendor/github.com/urfave/cli/command.go:174 +0x51e
github.com/containerd/containerd/vendor/github.com/urfave/cli.(*App).RunAsSubcommand(0xc00033e540, 0xc0000ed080, 0x0, 0x0)
        /home/runner/work/containerd/containerd/src/github.com/containerd/containerd/vendor/github.com/urfave/cli/app.go:404 +0x86b
github.com/containerd/containerd/vendor/github.com/urfave/cli.Command.startApp(0x555851257086, 0xa, 0x0, 0x0, 0x555851ef9200, 0x2, 0x2, 0x55585125d8ce, 0x11, 0x0, ...)
        /home/runner/work/containerd/containerd/src/github.com/containerd/containerd/vendor/github.com/urfave/cli/command.go:329 +0x847
github.com/containerd/containerd/vendor/github.com/urfave/cli.Command.Run(0x555851257086, 0xa, 0x0, 0x0, 0x555851ef9200, 0x2, 0x2, 0x55585125d8ce, 0x11, 0x0, ...)
        /home/runner/work/containerd/containerd/src/github.com/containerd/containerd/vendor/github.com/urfave/cli/command.go:102 +0x9cc
github.com/containerd/containerd/vendor/github.com/urfave/cli.(*App).Run(0xc00033e380, 0xc0000ce000, 0x7, 0x7, 0x0, 0x0)
        /home/runner/work/containerd/containerd/src/github.com/containerd/containerd/vendor/github.com/urfave/cli/app.go:276 +0x71a
main.main()
        github.com/containerd/containerd/cmd/ctr/main.go:37 +0x134

Describe the results you expected:
new container created and task run

Output of containerd --version:

containerd github.com/containerd/containerd v1.4.0-106-gce4439a8.m ce4439a8151f77dc50adb655ab4852ee9c366589.m

Any other relevant information:
when i modify the code of the container_restore_opts.go, and build from the source code, it works
before:

// WithRestoreRuntime restores the runtime for the container
func WithRestoreRuntime(ctx context.Context, id string, client *Client, checkpoint Image, index *imagespec.Index) NewContainerOpts {
	return func(ctx context.Context, client *Client, c *containers.Container) error {
		name, ok := index.Annotations[checkpointRuntimeNameLabel]
		if !ok {
			return ErrRuntimeNameNotFoundInIndex
		}

		// restore options if present
		m, err := GetIndexByMediaType(index, images.MediaTypeContainerd1CheckpointRuntimeOptions)
		if err != nil {
			if err != ErrMediaTypeNotFound {
				return err
			}
		}
		var options *ptypes.Any
		if m != nil {
			store := client.ContentStore()
			data, err := content.ReadBlob(ctx, store, *m)
			if err != nil {
				return errors.Wrap(err, "unable to read checkpoint runtime")
			}
			if err := proto.Unmarshal(data, options); err != nil {
				return err
			}
		}

		c.Runtime = containers.RuntimeInfo{
			Name:    name,
			Options: options,
		}
		return nil
	}
} 

after:

// WithRestoreRuntime restores the runtime for the container
func WithRestoreRuntime(ctx context.Context, id string, client *Client, checkpoint Image, index *imagespec.Index) NewContainerOpts {
	return func(ctx context.Context, client *Client, c *containers.Container) error {
		name, ok := index.Annotations[checkpointRuntimeNameLabel]
		if !ok {
			return ErrRuntimeNameNotFoundInIndex
		}

		// restore options if present
		m, err := GetIndexByMediaType(index, images.MediaTypeContainerd1CheckpointRuntimeOptions)
		if err != nil {
			if err != ErrMediaTypeNotFound {
				return err
			}
		}
		var options ptypes.Any
		if m != nil {
			store := client.ContentStore()
			data, err := content.ReadBlob(ctx, store, *m)
			if err != nil {
				return errors.Wrap(err, "unable to read checkpoint runtime")
			}
			if err := proto.Unmarshal(data, &options); err != nil {
				return err
			}
		}

		c.Runtime = containers.RuntimeInfo{
			Name:    name,
			Options: &options,
		}
		return nil
	}
}

_

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions