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

Prevent FD leakage when calling fork(2)+exec(2) #558

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Prevent FD leakage when calling fork(2)+exec(2) #558

wants to merge 4 commits into from

Conversation

feliperuiz
Copy link

I couldn't think of a better way to test this behavior, but I'm open to suggestions.

This should resolve #555.

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.
Copy link
Contributor

@zuiderkwast zuiderkwast left a comment

Choose a reason for hiding this comment

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

This is good stuff.

I think it should be rebased/rewritten using redisConnectWithOptions.

@michael-grunder michael-grunder self-assigned this Sep 7, 2022
@michael-grunder
Copy link
Collaborator

I'll merge the commits and rework the logic to use redisConnectWithOptions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

File descriptor handlers leak on fork + exec
3 participants