Skip to content

fix(server): raise the RLIMIT_NOFILE soft limit at start-up - #248

Closed
llying-001 wants to merge 1 commit into
mainfrom
llying/server-nofile
Closed

llying-001 wants to merge 1 commit into
mainfrom
llying/server-nofile

Conversation

@llying-001

Copy link
Copy Markdown
Contributor

Description

Every proxied PD request holds a client, a prefill and a decode connection, so a container's default soft limit of 1024
open files runs out at a few hundred concurrent requests: accept() fails with EMFILE and the router answers 502. On a
GLM-5.2 PD deployment under AgentX traffic the router logged OSError: [Errno 24] Too many open files 2,048 times in
the warm-up, then four requests (one of them a root request) got 502 prefill leg failed and the run aborted. The
router held 1,150-1,470 descriptors at peak under that load (not a leak). We had been working around it with
docker run --ulimit nofile=1048576.

This lifts the soft limit to the hard limit (1M when the hard limit is unlimited) before the backend is chosen, so the
Python router and the Rust router (which inherits it across exec) both get it. The same idea as #239 for
RLIMIT_MEMLOCK in the engine workers.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Changes

  • infera/server/__main__.py: raise RLIMIT_NOFILE's soft limit to the hard limit (capped at 1M when unlimited) at
    start-up; a refused setrlimit is logged and start-up continues.

Validation

  • Python unit tests (pytest -m "not slow and not integration", Python 3.10): 3,058 passed (main 3,054), no new
    failures. New tests/unit/server/test_nofile_limit.py: raised to the hard limit, unlimited hard limit, already at the
    limit, setrlimit failure.
  • pre-commit run --files <changed files> passes.
  • Our deployments used --ulimit nofile=1048576 (which raises both limits) since the failure above, so this change has
    not been exercised end to end on its own; it removes the need for that flag.

AI assistance was used to write this change and description.

Checklist:

  • The functionality is complete
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Every proxied PD request holds a client, a prefill and a decode
connection, so a container's default soft limit of 1024 open files runs
out at a few hundred concurrent requests: accept() fails with EMFILE and
the router answers 502. Lift the soft limit to the hard limit (1M when the
hard limit is unlimited) before the backend is chosen, so the Rust router
inherits it across exec.

Tests: tests/unit/server/test_nofile_limit.py (raised to the hard limit,
unlimited hard limit, already at the limit, setrlimit failure).

Signed-off-by: liyingli <liyingli@amd.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
llying-001 added a commit that referenced this pull request Nov 19, 2026
…y repo at the user's request: AMD-AGI/Infera #246 (U16) #247 (U24) #248 (U14) #249 (U15) #250 (U28) #251 (U7), branches llying/<topic>, conventional titles; fork PRs llying-001/Infera #1-#6 closed and pointed at them

Signed-off-by: liyingli <liyingli@amd.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@llying-001
llying-001 marked this pull request as ready for review November 23, 2026 14:21
Copilot AI balanced review requested due to automatic review settings November 23, 2026 14:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues block the startup open-file limit adjustment.

No open issues 🎉

What changed in this PR

This PR raises the router’s open-file soft limit at startup to help prevent connection failures under high concurrent PD request load. It applies before backend selection, covering both the Python router and the Rust router launched via exec.

Changes:

  • Raises the soft limit to the hard limit, targeting 1,048,576 when the hard limit is unlimited.
  • Logs rejected limit changes without aborting startup.
  • Adds unit tests for finite and unlimited limits, already-equal limits, and rejected changes.
File Description
tests/​unit/​server/​test_nofile_limit.py Tests limit adjustments, no-op behavior, and failure handling.
infera/​server/​__main__.py Adds the limit-raising helper and calls it before backend selection.

Review effort: Balanced

@llying-001

Copy link
Copy Markdown
Contributor Author

Folded into #256 (GLM-5.2 vLLM P4D4 example, image and the infera changes it needs); the commit is carried there unchanged.

@llying-001 llying-001 closed this Nov 30, 2026
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.

2 participants