Fix #10968: spawnProcess fails when RLIMIT_NOFILE exceeds int.max#10969
Open
Poita wants to merge 2 commits intodlang:masterfrom
Open
Fix #10968: spawnProcess fails when RLIMIT_NOFILE exceeds int.max#10969Poita wants to merge 2 commits intodlang:masterfrom
Poita wants to merge 2 commits intodlang:masterfrom
Conversation
When RLIMIT_NOFILE is set to unlimited (RLIM_INFINITY), r.rlim_cur is a huge value (e.g. 2^63-1). The cast(int) on this value wraps to -1, which causes the /dev/fd fast path to be skipped (since -1 < 128K) and the poll() path to attempt a massive malloc that fails. This manifests as "Failed to allocate memory (Cannot allocate memory)" on any process spawn, making dub completely unusable on systems with unlimited file descriptor limits (common on macOS). Fix by: - Using long instead of cast(int) for maxDescriptors - Always trying /dev/fd enumeration first (it's the most efficient path and works regardless of the limit value) - Capping the slow close() fallback to 1M descriptors to avoid iterating over billions when the limit is huge Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Regression test that sets RLIMIT_NOFILE above int.max and verifies process spawning still works. Without the previous fix, this triggers "Failed to allocate memory" due to integer overflow in the fd-closing code. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
|
Thanks for your pull request and interest in making D better, @Poita! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub run digger -- build "master + phobos#10969" |
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.
Fix #10968
Summary
When
RLIMIT_NOFILEis unlimited or exceedsint.max,spawnProcessfails with "Cannot allocate memory" due to integer overflow in the fd-closing code afterfork().Changes
longinstead ofcast(int)formaxDescriptorsto preserve the actualrlim_curvalue/dev/fd(or/proc/self/fd) enumeration first, regardless of the limit value — this is the most efficient path and avoids themallocentirelyRLIMIT_NOFILEaboveint.maxand verifies process spawning worksRoot cause
cast(int)ofRLIM_INFINITY(2^63-1) wraps to-1, which:/dev/fdenumeration path (since-1 < 128K)poll()path which tries tomalloca huge buffer and failsTesting
std.processand passes with the fix