{{ message }}
Repository navigation
Close all inherited file descriptors in restartServer() - #15992
Open
Mohak51234 wants to merge 1 commit into
Open
Mohak51234 wants to merge 1 commit into
Mohak51234 wants to merge 1 commit into
Conversation
Author
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.

Fixes #15860
Problem
restartServer()(used byDEBUG RESTART) is meant to close every inherited file descriptor except stdin/stdout/stderr beforeexecve(), but its loop only covered[3, maxclients + 1024). A descriptor inherited from the parent at a higher number, withoutFD_CLOEXEC, stayed open in the restarted process.Change
Added
closeInheritedFds()insrc/server.c:close_range(3, ~0U, 0)closes everything in one syscall./proc/self/fd(or/dev/fd), find the highest open descriptor, and close up to it.restartServer()now calls it instead of the fixed-bound loop.Testing
maxclients 100): before the change fd 1500 stays open afterDEBUG RESTART, after the change both fds are closed.tests/unit/other.tclthat starts a server from a shell with fd 1500 open andmaxclients 100, runsDEBUG RESTART, and checks the descriptor is gone. It fails without the change and passes with it.close_rangebranch; both fds still closed./dev/fdpath for macOS/BSD is untested. The new test is Linux-only (reads/proc).Note
Medium Risk
Changes process restart/exec hygiene; wrong FD closure could affect restart or child processes, but scope is limited to DEBUG RESTART rather than normal request handling.
Overview
Fixes incomplete FD cleanup before
execve()inrestartServer()(used byDEBUG RESTART): the old loop only closed descriptors up tomaxclients + 1024, so inherited fds above that could leak into the restarted process.closeInheritedFds()replaces that loop—on Linux it triesclose_range(3, UINT_MAX)first, otherwise scans/proc/self/fdor/dev/fdfor the highest open fd and closes through it, with the previous bound as a last resort. Valgrind-safefcntl/closebehavior is unchanged.A Linux-only regression test in
tests/unit/other.tclstarts a server with fd 1500 inherited and asserts it is gone afterDEBUG RESTART.Reviewed by Cursor Bugbot for commit 89c7a76. Bugbot is set up for automated code reviews on this repo. Configure here.