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

Fix File to Close #4004

Merged
merged 1 commit into from
Sep 1, 2023
Merged

Conversation

hangscer8
Copy link
Contributor

Need close file in time.

Signed-off-by: hang.jiang <hang.jiang@daocloud.io>
Copy link
Member

@lifubang lifubang left a comment

Choose a reason for hiding this comment

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

LGTM
Furthermore, do you know whether there is a way to detect such errors automatically or not?

@kolyshkin
Copy link
Contributor

@hangscer8 thanks, LGTM.

Furthermore, do you know whether there is a way to detect such errors automatically or not?

One way is to do a runtime check. I have added a test case doing that in #2802 (further improved in #3735). Problem is, it does not test every code path, and only checks for those leaks that are not a one-time thing. Thus, it does not detect issues fixed in this PR, because:

  1. tryDefaultCgroupRoot is only called once.
  2. The "leak" in update.go is not a leak, since it's in a short-lived binary (runc update) which frees all resources (incl. open file descriptors) upon exiting.

One other thing to note is, Go uses runtime.SetFinalizer to call close on every os.File which is being garbage-collected, meaning that close will be called implicitly and eventually -- some time after the file variable goes out of scope and is garbage-collected. Surely we should still close all fds explicitly nevertheless.

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

@kolyshkin kolyshkin merged commit 8feecba into opencontainers:main Sep 1, 2023
36 checks passed
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