Skip to content

Conversation

astrawind
Copy link
Contributor

Add missing defer conn.Close().

Add missing defer conn.Close().

Signed-off-by: Pavel Liubimov <[email protected]>
@kolyshkin kolyshkin requested a review from rata July 2, 2025 01:18
Copy link
Member

@rata rata 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!

I thought the defer done after the type assert would close the connection. But checking the documentation it does not:

File returns a copy of the underlying os.File. It is the caller's responsibility to close f when finished. Closing c does not affect f, and closing f does not affect c.

I wonder if that code-path can be simplified. But let's start with this fix :)

@rata
Copy link
Member

rata commented Jul 2, 2025

Test failures seem unrelated, restarted the failed tests

@lifubang lifubang added backport/1.2-todo A PR in main branch which needs to be backported to release-1.2 backport/1.3-todo A PR in main branch which needs to be backported to release-1.3 labels Jul 2, 2025
@lifubang
Copy link
Member

lifubang commented Jul 2, 2025

In fact, we will close all unneeded fds before execve the container process, so it won’t cause resource leaks. But we shouldn't rely too much on this fallback logic. Thanks.

@lifubang
Copy link
Member

lifubang commented Jul 3, 2025

In fact, we will close all unneeded fds before execve the container process, so it won’t cause resource leaks.

This is wrong, because the function sendContainerProcessState is called in runc main process, and if we start a large number of containers concurrently — especially those without detach — it can result in a large number of open FDs being held in the runc parent process. Furthermore, these FDs may maintain long-lived connections to the seccomp listener, increasing the risk of resource exhaustion.

@lifubang lifubang merged commit 4d4cedd into opencontainers:main Jul 3, 2025
43 of 45 checks passed
@lifubang
Copy link
Member

lifubang commented Jul 3, 2025

@astrawind Could you help to open backport PRs for release-1.2 and release-1.3?

@kolyshkin kolyshkin added backport/1.2-done A PR in main branch which has been backported to release-1.2 backport/1.3-done A PR in main branch which has been backported to release-1.3 and removed backport/1.2-todo A PR in main branch which needs to be backported to release-1.2 backport/1.3-todo A PR in main branch which needs to be backported to release-1.3 labels Jul 3, 2025
@rata
Copy link
Member

rata commented Jul 7, 2025

@lifubang

This is wrong, because the function sendContainerProcessState is called in runc main process

Exactly, this should be in the parent and not affect the container process.

This is wrong, because the function sendContainerProcessState is called in runc main process, and if we start a large number of containers concurrently — especially those without detach — it can result in a large number of open FDs being held in the runc parent process. Furthermore, these FDs may maintain long-lived connections to the seccomp listener, increasing the risk of resource exhaustion.

Not sure I follow, what is the issue? If we start a lot of containers, then we will start the runc parent binary a lot of times, right? I'm not sure I follow your concern here. Can you please elaborate?

@lifubang
Copy link
Member

lifubang commented Jul 9, 2025

If we start a lot of containers

concurrently

@rata
Copy link
Member

rata commented Jul 9, 2025

@lifubang yeap, if we start lot of container concurrently, what is the issue? I don't see how it can be a large number of open fds, as each container start creates a new process.

@lifubang
Copy link
Member

what is the issue?

Without this patch, runc will not release the socket connection after calling syncParentSeccomp (which occurs before the container process starts). If all processes reach this stage simultaneously, it could result in a large number of open file descriptors on the host. This issue becomes particularly significant when a TTY is used for communication with the container, as the associated socket connections may remain open indefinitely until the user logs out of the container.

@rata
Copy link
Member

rata commented Jul 11, 2025

@lifubang I don't see it, what am I missing?

The process that has this connection open dies when the container starts. And each process won't have more than 1 connection for this. How is it that if a tty is used any of this changes? And what is the issue if several process on the host have one connection open? This connection might be closed when the process dies, but the concurrency is the same if you time it enough to be opened at the same time, even if we do the close.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/1.2-done A PR in main branch which has been backported to release-1.2 backport/1.3-done A PR in main branch which has been backported to release-1.3 kind/bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants