Repository navigation
fix(frontend): raise soft RLIMIT_NOFILE at startup to avoid accept() EMFILE spiral #11802
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
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e724b1e
frontend: raise soft RLIMIT_NOFILE at startup to avoid accept() EMFIL…
mikekg 71c5a8d
Update components/src/dynamo/frontend/main.py
mikekg aa58280
frontend: move resource import to module scope
mikekg 9a9773a
fix(frontend): make fd-limit hardening Windows-safe
mikekg f672fd8
fix(frontend): make fd-limit target configurable via env
mikekg 1626577
fix(frontend): don't reduce an already-unlimited fd soft limit
mikekg 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| """Platform-safety tests for the frontend fd-limit hardening (`_raise_fd_limit`). | ||
|
|
||
| `resource` is a Unix-only stdlib module, so the hardening must degrade to a | ||
| no-op on platforms without it (e.g. Windows) and must never break startup. | ||
| """ | ||
|
|
||
| import builtins | ||
|
|
||
| import pytest | ||
|
|
||
| from dynamo.frontend.main import FRONTEND_FD_LIMIT_TARGET, _raise_fd_limit | ||
|
|
||
| pytestmark = [ | ||
| pytest.mark.unit, | ||
| pytest.mark.gpu_0, | ||
| pytest.mark.pre_merge, | ||
| ] | ||
|
|
||
|
|
||
| def test_noop_when_resource_missing(monkeypatch): | ||
| """Simulate Windows: `import resource` fails -> clean no-op, not ImportError.""" | ||
| real_import = builtins.__import__ | ||
|
|
||
| def _no_resource(name, *args, **kwargs): | ||
| if name == "resource": | ||
| raise ImportError("simulated Windows: no `resource` module") | ||
| return real_import(name, *args, **kwargs) | ||
|
|
||
| monkeypatch.setattr(builtins, "__import__", _no_resource) | ||
| _raise_fd_limit() # must return cleanly | ||
|
|
||
|
|
||
| def test_swallows_setrlimit_failure(monkeypatch): | ||
| """A denied setrlimit (restricted environment) is swallowed best-effort.""" | ||
| resource = pytest.importorskip("resource") | ||
| monkeypatch.setattr(resource, "getrlimit", lambda _res: (64, 1_000_000)) | ||
|
|
||
| def _deny(*args, **kwargs): | ||
| raise ValueError("simulated: not permitted to raise the limit") | ||
|
|
||
| monkeypatch.setattr(resource, "setrlimit", _deny) | ||
| _raise_fd_limit() # must return cleanly despite setrlimit raising | ||
|
|
||
|
|
||
| def test_raises_limit_on_unix(monkeypatch): | ||
| """On Unix, the soft limit is lifted toward the target (bounded by hard).""" | ||
| resource = pytest.importorskip("resource") | ||
| captured = {} | ||
| monkeypatch.setattr(resource, "getrlimit", lambda _res: (64, 1_000_000)) | ||
| monkeypatch.setattr( | ||
| resource, "setrlimit", lambda _res, limits: captured.update(limits=limits) | ||
| ) | ||
| _raise_fd_limit(target=4096) | ||
| assert captured["limits"] == (4096, 1_000_000) | ||
|
|
||
|
|
||
| def test_noop_when_already_sufficient(monkeypatch): | ||
| """No setrlimit call when the soft limit already meets the target.""" | ||
| resource = pytest.importorskip("resource") | ||
| monkeypatch.setattr( | ||
| resource, "getrlimit", lambda _res: (FRONTEND_FD_LIMIT_TARGET, 1_000_000) | ||
| ) | ||
|
|
||
| def _fail(*args, **kwargs): | ||
| raise AssertionError("setrlimit must not be called when already sufficient") | ||
|
|
||
| monkeypatch.setattr(resource, "setrlimit", _fail) | ||
| _raise_fd_limit() # soft already == target -> no setrlimit |
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.