Skip to content

Fix file descriptor leaks of netns handles and sockets in netlink metrics collector.#522

Open
MrHohn wants to merge 1 commit into
GoogleCloudPlatform:masterfrom
MrHohn:fix-netd-fd-leak
Open

Fix file descriptor leaks of netns handles and sockets in netlink metrics collector.#522
MrHohn wants to merge 1 commit into
GoogleCloudPlatform:masterfrom
MrHohn:fix-netd-fd-leak

Conversation

@MrHohn

@MrHohn MrHohn commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator
  • Add defer basens.Close() in getSnapshots to release base network namespace file descriptor.
  • Defer a single cleanup function at the beginning of getSnapshots to close all open namespace handles in the namespaces slice on function exit.
  • Explicitly close the netlink socket s on every return path inside getSnapshots loop, and at the end of the iteration, removing the unsafe defer-inside-loop pattern.
  • Close ns handle in getNamespaces when unix.Fstat fails.

…rics collector.

- Add defer basens.Close() in getSnapshots to release base network namespace file descriptor.
- Defer a single cleanup function at the beginning of getSnapshots to close all open namespace handles in the namespaces slice on function exit.
- Explicitly close the netlink socket `s` on every return path inside getSnapshots loop, and at the end of the iteration, removing the unsafe defer-inside-loop pattern.
- Close `ns` handle in getNamespaces when unix.Fstat fails.
@MrHohn MrHohn requested a review from jingyuanliang June 23, 2026 20:18
@google-oss-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: MrHohn

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@MrHohn

MrHohn commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator Author

/assign @MaitreyPrajapati

@google-oss-prow

Copy link
Copy Markdown
Contributor

@MrHohn: GitHub didn't allow me to assign the following users: MaitreyPrajapati.

Note that only GoogleCloudPlatform members with read permissions, repo collaborators and people who have commented on this issue/PR can be assigned. Additionally, issues/PRs can only have 10 assignees at the same time.
For more information please see the contributor guide

Details

In response to this:

/assign @MaitreyPrajapati

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant