Repository navigation
util: manage SpawnProcess socket descriptors with RAII - #395
Open
javierpmateos wants to merge 1 commit into
Open
javierpmateos wants to merge 1 commit into
javierpmateos wants to merge 1 commit into
Conversation
SpawnProcess could leak file descriptors if the second SocketPair(), connect_info_to_args, or MakeArgv threw an exception. Use kj::AutoCloseFd to take ownership of the descriptors as soon as they're created. Release them when closing or returning them, keeping the existing error handling and child behavior unchanged. Do the same in the SocketPair() fallback path used when SOCK_CLOEXEC is not available. Add a test that throws from the callback and checks that its socket is closed.
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ReviewsSee the guideline and AI policy for information on the review process. |
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.
Follow-up to #394, based on ryanofsky's suggestion to use
kj::AutoCloseFdinstead of handling descriptor cleanup manually.SpawnProcess()could leak file descriptors if the secondSocketPair(),connect_info_to_args, orMakeArgv()threw an exception.This change wraps the descriptors in
kj::AutoCloseFdas soon as they're created, releasing them when they're explicitly closed or handed off. It also uses RAII in theSocketPair()fallback for platforms withoutSOCK_CLOEXEC. The existing close error handling and child behavior are preserved.Testing:
connect_info_to_argsand checks that the socket is closed. It fails on master and passes with this change.mptestcases pass, both normally and withSOCK_CLOEXECdisabled.strace: when the callback throws, all four descriptors are closed with this change, while master leaves them open.There are two minor differences: the fallback's
fcntlerror now includes the full expression, and on error paths two descriptors are closed after killing the child rather than before. Neither changes the intended behavior.This doesn't address unexpected exceptions after
fork()that could leave the child running.ReadSpawnResult()can't throw today, so this is only theoretical.I used an AI coding assistant for the implementation. I reviewed the diff and ran the tests myself.