Repository navigation
Close the stdin handle when an exec process exits - #2441
Open
costajohnt wants to merge 1 commit into
Open
costajohnt wants to merge 1 commit into
costajohnt wants to merge 1 commit into
Conversation
startExecProcess closed the stdout and stderr handles after the process exited but not stdin, so every `container exec -i` left one dup'd PIPE descriptor open in container-runtime-linux. stdin is closed with FileHandle.close() rather than close(2): the stdin relay's readabilityHandler can still be live when the process exits, and FileHandle.close() waits for that dispatch source to cancel before it closes the descriptor. Fixes apple#2439
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Type of Change
Motivation and Context
Fixes #2439.
startExecProcesscloses the exec's stdout and stderr handles once the process exits, but not stdin. Those handles come fromXPCMessage.fileHandle(key:), whichxpc_fd_dups the descriptor and wraps it withcloseOnDealloc: false, and Containerization only reads stdin through theReaderStreamconformance, so nothing else closes it. Everycontainer exec -itherefore leaves one PIPE open incontainer-runtime-linux.This closes stdin in the same place, after stdout and stderr. It uses
FileHandle.close()rather thancloseHandle(rawclose(2)) because the stdin relay'sreadabilityHandlercan still be installed when the process exits, for exampleyes | container exec -i c head -1. Raw-closing the descriptor while that dispatch source is live can run a pending callback against a closed (or reused) fd. In a standalone harness that mirrors this setup,availableDatathrewNSFileHandleOperationExceptionand aborted the process.FileHandle.close()defers the real close until the source is cancelled.Related: #2060 and #1928 also touch exec handle cleanup. This change is independent of both and stays correct if #1928 switches these handles to
closeOnDealloc: true, sinceFileHandle.close()marks the handle closed.Testing
Ran the reporter's
repro.pyfrom #2439 against analpine:3.20container, withmake alldebug builds ofmain(c6ca9a4) and this branch, each started withcontainer system start --app-root <dir>:execexec -iexec -imainAlso ran
yes | container exec -i fdtest head -130 times on this branch: the runtime stayed up with 0 PIPEs open. There's no test target for the Linux runtime helper today, so no automated test is added.