Skip to content

Conversation

@lifubang
Copy link
Member

@lifubang lifubang commented Jul 5, 2025

When reading freezer state, we can safely ignore the error in the following two common situations:

  1. The cgroup path does not exist at the time of opening(eg: the kernel is too old) — indicated by os.IsNotExist.
  2. The cgroup path is deleted during the seek/read operation — indicated by errors.Is(err, unix.ENODEV). These conditions are expected and do not require special handling.

Unfortunately, the second case was accidentally removed during a code refactoring. We should add it back to ensure correct error handling.

Fix: opencontainers/runc#4798

@kannon92
Copy link

kannon92 commented Jul 8, 2025

cc @kolyshkin

Copy link
Contributor

@kolyshkin kolyshkin left a comment

Choose a reason for hiding this comment

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

why not put ignore... into the same file, fs2/freezer.go? It is only used from 1 place.

@lifubang
Copy link
Member Author

lifubang commented Jul 9, 2025

why not put ignore... into the same file, fs2/freezer.go? It is only used from 1 place.

Just a thought for the future — I saw a similar logic in runc. Maybe we should move it to cgroups, as it could be useful later on.

For example:
https://github.com/opencontainers/runc/blob/main/libcontainer/factory_linux.go#L69-L78

@kolyshkin
Copy link
Contributor

why not put ignore... into the same file, fs2/freezer.go? It is only used from 1 place.

Just a thought for the future — I saw a similar logic in runc. Maybe we should move it to cgroups, as it could be useful later on.

For example: https://github.com/opencontainers/runc/blob/main/libcontainer/factory_linux.go#L69-L78

It is basically a one-liner and I'm not against reimplementing it a few times (rather than exposing as a public API).

When we expose something as a public API, people start depending on it, and then we change the logic (in this case that would be adding another errno, or removing one) people will complain that we break backward compatibility. So, as much as I'm in for code reuse,

  • this is not too much code to reuse;
  • this better not be added to public API.

We can safely ignore the error in the following two common situations:
1. The cgroup path does not exist at the time of opening(eg: the kernel is too old)
   — indicated by os.IsNotExist.
2. The cgroup path is deleted during the seek/read operation — indicated by
   errors.Is(err, unix.ENODEV).
These conditions are expected and do not require special handling.

Unfortunately, the second case was accidentally removed during a code refactoring.
We should add it back to ensure correct error handling.

Signed-off-by: lifubang <[email protected]>
@lifubang lifubang force-pushed the fix-getfreezer-error branch from 190c1ac to 6df7bae Compare July 9, 2025 09:55
@lifubang
Copy link
Member Author

lifubang commented Jul 9, 2025

When we expose something as a public API, people start depending on it, and then we change the logic (in this case that would be adding another errno, or removing one) people will complain that we break backward compatibility. So, as much as I'm in for code reuse,

Make sense, removed it now.

Copy link
Contributor

@kolyshkin kolyshkin left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

LGTM

// 2. The cgroup path is deleted during the seek/read operation — indicated by
// errors.Is(err, unix.ENODEV).
// These conditions are expected and do not require special handling.
if os.IsNotExist(err) || errors.Is(err, unix.ENODEV) {
Copy link
Member

Choose a reason for hiding this comment

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

Do you think we need to call out that we're deliberately using os.IsNotExist() here, instead of errors.Is (https://pkg.go.dev/os#IsNotExist) to prevent someone from updating the code, or would we be paying attention if that would happen?

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's address this as a followup.

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.

[bug] cgroup.freeze: no such device

4 participants