Skip to content

Conversation

@liubin
Copy link
Contributor

@liubin liubin commented Nov 11, 2022

In golang when copying a slice, if the slice is initialized with a desired length, then appending to it will cause the size to double.

Signed-off-by: bin liu [email protected]

@k8s-ci-robot
Copy link

Hi @liubin. Thanks for your PR.

I'm waiting for a containerd member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@liubin
Copy link
Contributor Author

liubin commented Nov 11, 2022

Indeed I got some errors like this:

Nov 07 09:53:31 ubuntu22-5550e0 containerd[79452]: time="2022-11-07T09:53:31.068338021Z" level=info msg="CreateContainer within sandbox "43de2af2291b8fd93618f551112de4cb317729aa6f26e32e4fc3cbbfc71eeba6" for &ContainerMetadata{Name:kube-controller-manager,Attempt:0,} returns container id """
Nov 07 09:53:31 ubuntu22-5550e0 containerd[79452]: panic: runtime error: invalid memory address or nil pointer dereference [recovered]
Nov 07 09:53:31 ubuntu22-5550e0 containerd[79452]: panic: runtime error: invalid memory address or nil pointer dereference
Nov 07 09:53:31 ubuntu22-5550e0 containerd[79452]: [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x55661ce6c65d]
Nov 07 09:53:31 ubuntu22-5550e0 containerd[79452]: goroutine 1583 [running]:
Nov 07 09:53:31 ubuntu22-5550e0 containerd[79452]: go.opentelemetry.io/otel/sdk/trace.(*recordingSpan).End.func1()
Nov 07 09:53:31 ubuntu22-5550e0 containerd[79452]: /go/src/github.com/containerd/containerd/vendor/go.opentelemetry.io/otel/sdk/trace/span.go:243 +0x2a
Nov 07 09:53:31 ubuntu22-5550e0 containerd[79452]: go.opentelemetry.io/otel/sdk/trace.(*recordingSpan).End(0xc000b19b00, {0x0, 0x0, 0x7f8a48032a40?})
Nov 07 09:53:31 ubuntu22-5550e0 containerd[79452]: /go/src/github.com/containerd/containerd/vendor/go.opentelemetry.io/otel/sdk/trace/span.go:282 +0x8a2
Nov 07 09:53:31 ubuntu22-5550e0 containerd[79452]: panic({0x55661d87afe0, 0x55661e695be0})
Nov 07 09:53:31 ubuntu22-5550e0 containerd[79452]: /usr/local/go/src/runtime/panic.go:838 +0x207
Nov 07 09:53:31 ubuntu22-5550e0 containerd[79452]: github.com/containerd/containerd/pkg/cri/store/container.deepCopyOf({0x0, 0x172544bbf4c9427b, 0x0, 0x0, 0x0, {0x0, 0x0}, {0x0, 0x0}, 0x0, ...})
Nov 07 09:53:31 ubuntu22-5550e0 containerd[79452]: /go/src/github.com/containerd/containerd/pkg/cri/store/container/status.go:226 +0x2dd
Nov 07 09:53:31 ubuntu22-5550e0 containerd[79452]: github.com/containerd/containerd/pkg/cri/store/container.(*statusStorage).Get(0xc000182e80?)
Nov 07 09:53:31 ubuntu22-5550e0 containerd[79452]: /go/src/github.com/containerd/containerd/pkg/cri/store/container/status.go:210 +0x145
Nov 07 09:53:31 ubuntu22-5550e0 containerd[79452]: github.com/containerd/containerd/pkg/cri/store/container.WithStatus.func1(0xc0013883c0)
Nov 07 09:53:31 ubuntu22-5550e0 containerd[79452]: /go/src/github.com/containerd/containerd/pkg/cri/store/container/container.go:81 +0xbc
Nov 07 09:53:31 ubuntu22-5550e0 containerd[79452]: github.com/containerd/containerd/pkg/cri/store/container.NewContainer({{0xc0010dd0c0, 0x40}, {0xc001257f10, 0x6e}, {0xc00109f340, 0x40}, 0xc0006161c0, {0xc000fb5720, 0x47}, {0xc000d42a80, ...}, ...}, ...)
Nov 07 09:53:31 ubuntu22-5550e0 containerd[79452]: /go/src/github.com/containerd/containerd/pkg/cri/store/container/container.go:96 +0x1cc
Nov 07 09:53:31 ubuntu22-5550e0 containerd[79452]: github.com/containerd/containerd/pkg/cri/server.(*criService).CreateContainer(0xc000640c00, {0x55661dac84a8, 0xc001284e10}, 0xc001284360)
Nov 07 09:53:31 ubuntu22-5550e0 containerd[79452]: /go/src/github.com/containerd/containerd/pkg/cri/server/container_create.go:262 +0x2dad

In golang when copy a slice, if the slice is initialized with a
desired length, then appending to it will cause the size double.

Signed-off-by: bin liu <[email protected]>
@AkihiroSuda AkihiroSuda changed the title Fix slice append error Fix slice append error (spec.Linux.Resources.HugepageLimits) Nov 11, 2022
@AkihiroSuda
Copy link
Member

/ok-to-test

Copy link
Member

@estesp estesp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@estesp estesp merged commit 135af6d into containerd:main Nov 11, 2022
mxpv added a commit to mxpv/containerd that referenced this pull request Jan 17, 2023
Signed-off-by: Maksym Pavlenko <[email protected]>
@mxpv mxpv added cherry-picked/sbserver Changes are backported to sbserver and removed cherry-pick/sbserver labels Jan 19, 2023

if spec.Linux.Resources.HugepageLimits != nil {
hugepageLimits := make([]*runtime.HugepageLimit, len(spec.Linux.Resources.HugepageLimits))
hugepageLimits := make([]*runtime.HugepageLimit, 0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the correct fix? Should this have been;

hugepageLimits := make([]*runtime.HugepageLimit, 0, len(spec.Linux.Resources.HugepageLimits))

(zero length, with an initial capacity of len(spec.Linux.Resources.HugepageLimits)) ?

@thaJeztah thaJeztah added cherry-picked/1.6.x PR commits are cherry-picked into release/1.6 branch and removed cherry-pick/1.6.x labels Jan 24, 2023
@thaJeztah
Copy link
Member

Opened a cherry-pick for 1.6 (#7995), but looks like this code is not in 1.5 (unless it was moved from somewhere else)

jsturtevant pushed a commit to jsturtevant/containerd that referenced this pull request Sep 21, 2023
Signed-off-by: Maksym Pavlenko <[email protected]>
kiashok pushed a commit to kiashok/containerd that referenced this pull request Oct 23, 2024
Signed-off-by: Maksym Pavlenko <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cherry-picked/sbserver Changes are backported to sbserver cherry-picked/1.6.x PR commits are cherry-picked into release/1.6 branch ok-to-test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants