Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cgroup.go: avoid panic on nil interface #207

Merged
merged 1 commit into from
Sep 9, 2021

Conversation

linrl3
Copy link
Contributor

@linrl3 linrl3 commented Sep 8, 2021

Hi, this PR's related issue is #205, which is a potential nil interface panic case.

In https://github.com/containerd/cgroups/blob/main/cgroup.go#L330, if we pass a subsystem that doesn't exist into func (c *cgroup) Processes(subsystem Name, recursive bool), we would get a panic: interface conversion: interface is nil, not cgroups.pather.

So we'd check nil interface and return error if it's nil to avoid panic.

@@ -323,6 +323,9 @@ func (c *cgroup) Tasks(subsystem Name, recursive bool) ([]Task, error) {

func (c *cgroup) processes(subsystem Name, recursive bool, pType procType) ([]Process, error) {
s := c.getSubsystem(subsystem)
if s == nil {
return nil, ErrControllerNotActive
}
sp, err := c.path(subsystem)
if err != nil {
return nil, err
Copy link
Member

Choose a reason for hiding this comment

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

I was rethinking that error message. I think the following code might be more clear for the error

After Line 329,

if s == nil {
return nil, errors.Errorf("no such cgroup %s in subsystem %s", sp, subsystem)
}

WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could we define a new Error with this?

Copy link
Member

Choose a reason for hiding this comment

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

os.ErrNotExist for errors.Wrapf ?

Copy link
Member

@fuweid fuweid Sep 9, 2021

Choose a reason for hiding this comment

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

I think os.ErrNotExist is fine 😃

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was thinking something like

var ErrCgroupNotInSubsystem = errors.New("cgroups: cgroup not in subsystem")

Copy link
Member

Choose a reason for hiding this comment

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

I was thinking something like


var ErrCgroupNotInSubsystem = errors.New("cgroups: cgroup not in subsystem")

The error doesn't contain the which subsystem and which cgroup. That is My concern

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, we should make it clear

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could we use fmt.Errorf("cgroups: %s doesn't exist in %s subsystem", sp, subsystem) ?

Copy link
Member

Choose a reason for hiding this comment

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

Could we use fmt.Errorf("cgroups: %s doesn't exist in %s subsystem", sp, subsystem) ?

sgtm

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A new commit had been pushed.

Copy link
Member

@fuweid fuweid left a comment

Choose a reason for hiding this comment

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

LGTM

@AkihiroSuda AkihiroSuda merged commit 90010ec into containerd:main Sep 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants