Fix early stdio close due to multiple ownership #1655
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 aRawFd
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 toread_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 ofAsyncWrite
and introduces a newTerminalFd
which wraps the pty file descriptor and implementsAsyncRead
andAsyncWrite
for references to itself. This allows us to use reference counting to close the file descriptor only after both theread_loop_stdin
andread_loop
terminate.Which issue(s) this PR fixes:
None
Special notes for your reviewer:
Does this PR introduce a user-facing change?