Skip to content

util_linux: add connection close in setupIO #4780

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mi4r
Copy link

@mi4r mi4r commented Jun 9, 2025

If an error occurs while creating a file descriptor using socket, err := uc.File(), this error is returned to the calling runner.run function. The runner.run function also simply returns this error, and, as a result, the connection created in the line conn, err := net.Dial("unix", sockpath) remains open.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

If an error occurs while creating a file descriptor using
socket, err := uc.File(), this error is returned to the calling
runner.run function. The runner.run function also simply returns
this error, and, as a result, the connection created in the line
conn, err := net.Dial("unix", sockpath) remains open.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Signed-off-by: Tigran Sogomonian <[email protected]>
@@ -123,11 +123,13 @@ func setupIO(process *libcontainer.Process, container *libcontainer.Container, c
}
uc, ok := conn.(*net.UnixConn)
if !ok {
conn.Close()
Copy link
Member

Choose a reason for hiding this comment

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

Thank you for your contribution.

In practice, omitting these close operations doesn't cause any harm, since runc will exit anyway if an error occurs during the setupIO call.

However, from a code style and best practices perspective, I think we should always close the socket connection once an error is encountered after the connection has been established.

Considering both aspects, LGTM.

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.

2 participants