Skip to content

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.

@fuweid fuweid requested a review from AkihiroSuda September 9, 2021 08:13
@linrl3 linrl3 force-pushed the topic/nil-interface-bug branch from 6aeb1eb to d55de5d Compare September 9, 2021 12:44
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