Prevent FD leakage when calling fork(2)+exec(2) #558
Open
feliperuiz wants to merge 4 commits intoredis:masterfrom
feliperuiz:set-cloexec
Open
Prevent FD leakage when calling fork(2)+exec(2) #558feliperuiz wants to merge 4 commits intoredis:masterfrom feliperuiz:set-cloexec
feliperuiz wants to merge 4 commits intoredis:masterfrom
feliperuiz:set-cloexec
Conversation
In order to prevent file descriptor leakage when calling fork(2)+exec(2), the FD_CLOEXEC flag needs to be set. Just setting the flag using fcntl(2) after socket creation is, however, not enough, since, in a multi-threaded application, another thread might fork after we created the socket but before we had the chance of setting the flag. To remedy this, Linux introduced the SOCK_CLOEXEC flag in 2.6.27, to be set on socket creation. At the time of this commit, it has been ported to other systems, such as FreeBSD. Should the flag not be available, as is the case in macOS or older versions of the Linux kernel, we do the next best thing, which is trying to call fcntl(2) right after socket creation.
MacOS doesn't have procfs, which is what we were using for testing.
zuiderkwast
reviewed
Sep 1, 2022
Contributor
zuiderkwast
left a comment
There was a problem hiding this comment.
This is good stuff.
I think it should be rebased/rewritten using redisConnectWithOptions.
Collaborator
|
I'll merge the commits and rework the logic to use |
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.
I couldn't think of a better way to test this behavior, but I'm open to suggestions.
This should resolve #555.