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 early stdio close due to multiple ownership #1655

Merged

Conversation

mgjm
Copy link
Contributor

@mgjm mgjm commented Aug 29, 2023

What type of PR is this?

/kind bug

What this PR does / why we need it:

The ContainerIO::read_loop_stdin function was taking the fd to stdin as a RawFd and took ownership of the file descriptor. This worked for piped IO (streams.rs) but not for tty based IO (terminal.rs).

With tty based IO the same file descriptor was used as an AsyncFd and passed to read_loop_stdin this resulted in two owners of the same file descriptor. The first owner (stdin in most cases) would close the fd on drop. The second owner would stall as it won't be notified that the fd closed and once the second owner would drop it would try to close the same fd again. Which could have been reused in the meantime.

This change refactors ContainerIO::read_loop_stdin to take an implementation of AsyncWrite and introduces a new TerminalFd which wraps the pty file descriptor and implements AsyncRead and AsyncWrite for references to itself. This allows us to use reference counting to close the file descriptor only after both the read_loop_stdin and read_loop terminate.

Which issue(s) this PR fixes:

None

Special notes for your reviewer:

Does this PR introduce a user-facing change?

None

Signed-off-by: Martin Michaelis <code@mgjm.de>
Copy link
Member

@saschagrunert saschagrunert left a comment

Choose a reason for hiding this comment

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

That's a good one, thank you for this fix!

@haircommander @rphillips PTAL

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Aug 29, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: mgjm, saschagrunert

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

The pull request process is described here

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

@haircommander
Copy link
Collaborator

/lgtm

great find!

@openshift-ci openshift-ci bot added the lgtm label Aug 29, 2023
@openshift-merge-robot openshift-merge-robot merged commit b5bdcb8 into containers:main Aug 29, 2023
31 checks passed
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.

None yet

4 participants