-
Notifications
You must be signed in to change notification settings - Fork 109
fix(openfiles): share descriptors across cloned shell contexts #1181
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
Merged
+144
−73
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| name: "File descriptor management" | ||
| # Regression tests for issue #1173: nested/concurrent shell constructs must not | ||
| # exhaust the process-wide file-descriptor table. | ||
| # | ||
| # brush runs subshells, command substitutions, background jobs, and function | ||
| # call contexts as in-process tasks rather than via fork(2), so they all share a | ||
| # single process-wide descriptor table. Each context inherits the caller's open | ||
| # files; sharing those descriptors -- rather than giving each context its own | ||
| # copy -- is what keeps deeply nested or highly concurrent scripts within the | ||
| # limit. A real shell gives each forked subshell its own descriptor table and so | ||
| # stays well within the limit too. | ||
| # | ||
| # Each case lowers the descriptor limit with `ulimit -n` and runs a workload that | ||
| # stays within the limit only when inherited descriptors are shared across | ||
| # contexts; if each context copied them, the workload would exceed the limit and | ||
| # fail with "Too many open files" and truncated output. The limits leave the | ||
| # correct (sharing) behavior several-fold headroom. These cases assume Unix | ||
| # `ulimit -n` semantics. | ||
| cases: | ||
| # Concurrent fan-out: every backgrounded job is alive simultaneously (they are | ||
| # all launched before `wait`), so copying the inherited descriptors per job | ||
| # would multiply the live descriptor count by the number of jobs. | ||
| - name: "Many concurrent background jobs each using command substitution" | ||
| incompatible_platforms: ["wasi"] | ||
| args: | ||
| - "-c" | ||
| - | | ||
| ulimit -n 256 || exit 1 | ||
| emit() { | ||
| local v | ||
| v=$(echo "$1") | ||
| echo "$v" | ||
| } | ||
| ( for i in $(seq 1 60); do emit "$i" & done; wait ) | wc -l | tr -d ' ' | ||
|
|
||
| # nvm-style: backgrounded jobs in a subshell, piped to a filter, each touching | ||
| # /dev/null via redirects -- the precise shape that exhausted descriptors in | ||
| # `nvm ls`. | ||
| - name: "Subshell of backgrounded jobs with redirects piped to a filter" | ||
| incompatible_platforms: ["wasi"] | ||
| args: | ||
| - "-c" | ||
| - | | ||
| ulimit -n 256 || exit 1 | ||
| work() { | ||
| local v | ||
| v=$(echo "alias-$1" 2>/dev/null) | ||
| echo "$v" 2>/dev/null | ||
| } | ||
| ( for i in $(seq 1 50); do work "$i" 2>/dev/null & done; wait ) | sort | wc -l | tr -d ' ' | ||
|
|
||
| # Nested depth: each command-substitution level keeps its ancestors' contexts | ||
| # alive while it runs, so copying inherited descriptors would grow the live | ||
| # count with nesting depth. | ||
| - name: "Deeply nested command substitution with redirects stays within the fd limit" | ||
| incompatible_platforms: ["wasi"] | ||
| args: | ||
| - "-c" | ||
| - | | ||
| ulimit -n 256 || exit 1 | ||
| rec() { | ||
| local n=$1 | ||
| if [ "$n" -le 0 ]; then | ||
| printf 'x' 2>/dev/null | ||
| return | ||
| fi | ||
| local inner | ||
| inner=$(rec $((n - 1)) 2>/dev/null) | ||
| printf '%s' "$inner" 2>/dev/null | ||
| } | ||
| out=$(rec 40) | ||
| echo "${#out}" |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.