Skip to content

fix(server): raise the open-file limit at start, and say when accepts run out of descriptors - #294

Closed
plotarmordev wants to merge 1 commit into
ashhart:mainfrom
plotarmordev:fix/server-accept-descriptor-limit
Closed

plotarmordev wants to merge 1 commit into
ashhart:mainfrom
plotarmordev:fix/server-accept-descriptor-limit

Conversation

@plotarmordev

Copy link
Copy Markdown
Contributor

What this changes

Fixes #293. The server raises its soft open-file limit (RLIMIT_NOFILE) to the hard limit at start, so idle connections can't exhaust a default 1024. When accept() still fails for want of descriptors, it prints one line for the run and waits 0.1 s before the next try. Before, socketserver dropped the EMFILE silently and the accept loop spun a core at 100 %. Both servers share Server; the new code is in server/descriptors.py.

Receipt

  • Environment: TensorFold 0.6.3 (9356df5), PyTorch 2.13.0a0, one DGX Spark (GB10, CUDA 13.3, driver 580), Vontra/Qwen3.8-Flash-Next-MLX-4bit-MTP @ dadefa80, --parallel 1 --context 16384, in Docker. Idle keep-alive connections opened in steps of 50 up to 900, then one chat request, then the connections closed and one more request.

    open files (soft / hard) 900 idle connections request while held log server CPU while held
    0.6.3, Docker default 1024 / 524288 connects stop at ~600 times out (30 s) nothing 100 %
    0.6.3, --ulimit nofile=1024:1024 1024 / 1024 connects stop at ~600 times out nothing 100 %
    this PR, Docker default 524288 / 524288 all 900 held HTTP 200, 0.4 s nothing 0.2 %
    this PR, --ulimit nofile=1024:1024 1024 / 1024 connects stop at ~600 times out one line 0.3 %

    The log line: [tensorfold] out of file descriptors (Too many open files): new connections wait until open ones close; raise the open-file limit (ulimit -n). In every case the next request after the connections close answers in 0.1-0.4 s.

  • Exactness: not applicable. Replies don't go through this code.

  • Decode speed: not applicable.

  • Prompt speed: not applicable.

  • Tests run:

    • New tests/test_server_descriptors.py, in subprocesses (process-wide limits). A server started with soft limit 256 raises it to the hard limit. An accept refused for want of descriptors prints once per run and again after the next accept succeeds. Both fail at 0.6.3 and pass with this change.
    • tests/test_server*.py tests/test_cuda_server*.py on CPU: 318 passed, 1 skipped (0.6.3 with the new file: 316 passed, the 2 new tests failed).
  • Not run, and why: the Mac server. resource exists on macOS; when the hard limit is unlimited it tries 65536, then 10240, and keeps the current limit if neither is allowed. I have no Mac to check that path. Windows has no resource and is unchanged.

Checklist

  • Every token still goes through the lane rounds. No serial path, and nothing that needs drafts off.
  • Drafted output equals "draft": false, a resumed prompt equals a fresh one, and concurrent equals solo.
  • No precision traded for speed. If the bits change, the description says which sums change and why.
  • Prompt processing is no slower than the last release.
  • The description says which platforms I ran, Metal M1 to M5 and CUDA, and which I could not.
  • New tests fail before the change, pass after it, and skip cleanly without their dependency.
  • Comments and docstrings are one line. No measurements or history in the source.
  • No personal data, machine names, internal hosts or local paths. No AI attribution lines.

… run out of descriptors

With Docker's default 1024 descriptors an idle Flash Next server already holds 427, so about 600 idle
connections exhaust the rest. accept() then fails with EMFILE, and socketserver drops that error without
a word: clients hang, the log stays empty, and the accept loop spins a core at 100% (ashhart#293).

The server now raises its soft RLIMIT_NOFILE to the hard limit at start. When accept() still fails for
want of descriptors it prints one line for the run (again after the next accept succeeds) and waits
0.1 s before the next try. Both servers share Server, so this covers the Mac and CUDA servers.
@ashhart ashhart mentioned this pull request Oct 3, 2026
ashhart added a commit that referenced this pull request Oct 6, 2026
…runs out of descriptors

From PR #294. Before it listens, the server raises its soft RLIMIT_NOFILE to the
hard limit, so idle keep-alive connections cannot exhaust a default of 256 or
1024. When the hard limit reads as unlimited it tries 65536, then 10240, and
never sets an unlimited soft limit. A limit already high enough is left alone, a
refused raise keeps the current one, and a raise logs the old and new values.

When accept fails for lack of descriptors (EMFILE or ENFILE), the listener logs
one line per burst, naming the error and saying to raise ulimit -n, and keeps
its 10 ms backoff.

zig build test now runs the server's unit tests (zig/src/server/root.zig),
including a raise from a lowered soft limit and the once-per-burst rule.

Co-authored-by: plotarmordev <[email protected]>
@ashhart

ashhart commented Oct 6, 2026

Copy link
Copy Markdown
Owner

Thank you, @plotarmordev. This landed in the Zig engine as 267cd3c, with your credit.

The Zig server never had the spin, since its accept loop already backed off for 10 ms when descriptors ran out. It lacked your other two pieces and now has both. At start it raises the soft open-file limit to the hard limit, with your 65536 and 10240 fallbacks when the hard limit reads as unlimited. macOS reports it that way, so the Mac path you couldn't test is the one that runs there. When accept still runs out of descriptors, the server logs one line a burst instead of retrying quietly. That covers what you reported in #293, which closes with this.

The Python engine is frozen (#286), so this PR closes with that. Thanks for the clear repro on a GB10.

@ashhart ashhart closed this Oct 6, 2026
grearjake-star added a commit to grearjake-star/TensorFold that referenced this pull request Oct 8, 2026
…out of descriptors

With the default soft limit of 1024 descriptors the server silently stopped accepting connections at
about 600 idle keep-alive connections: new connects sat in the backlog, requests hung, nothing was
logged and the accept loop spun a core. The server now raises its soft RLIMIT_NOFILE to the hard limit
at start, and when accept() still fails for want of descriptors it prints one line for the burst and
waits 0.1 s before the next try. The CUDA server uses this Server class.

Upstream: ashhart#294 (fixes ashhart#293), closed unmerged with the Python engine frozen; the
maintainer landed the same two pieces in the Zig server.

Co-authored-by: plotarmordev <[email protected]>
Bizuayeu added a commit to Bizuayeu/TensorFold that referenced this pull request Oct 12, 2026
…erver listens


With a container's default 1024 descriptors, idle connections can use up the rest, and the
server then waits on every accept. The listener already said so once a burst and backed
off; it now also raises the soft RLIMIT_NOFILE to the hard limit when it opens (65536, then
10240, when the hard limit is unlimited), as the 2.x line has done since 2.5.0 (TensorFold
ashhart#294 by plotarmordev). A failure to raise it leaves the limit as it was.
Bizuayeu added a commit to Bizuayeu/TensorFold that referenced this pull request Oct 13, 2026
…erver listens

With a container's default 1024 descriptors, idle connections can use up the rest, and the
server then waits on every accept. The listener already said so once a burst and backed
off; it now also raises the soft RLIMIT_NOFILE to the hard limit when it opens (65536, then
10240, when the hard limit is unlimited), as ashhart#294 (by plotarmordev) did for the Python
engine. A failure to raise it leaves the limit as it was.
Bizuayeu added a commit to Bizuayeu/TensorFold that referenced this pull request Oct 13, 2026
…erver listens

With a container's default 1024 descriptors, idle connections can use up the rest, and the
server then waits on every accept. The listener already said so once a burst and backed
off; it now also raises the soft RLIMIT_NOFILE to the hard limit when it opens (65536, then
10240, when the hard limit is unlimited), as ashhart#294 (by plotarmordev) did for the Python
engine. A failure to raise it leaves the limit as it was.
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
…runs out of descriptors

From PR ashhart#294. Before it listens, the server raises its soft RLIMIT_NOFILE to the
hard limit, so idle keep-alive connections cannot exhaust a default of 256 or
1024. When the hard limit reads as unlimited it tries 65536, then 10240, and
never sets an unlimited soft limit. A limit already high enough is left alone, a
refused raise keeps the current one, and a raise logs the old and new values.

When accept fails for lack of descriptors (EMFILE or ENFILE), the listener logs
one line per burst, naming the error and saying to raise ulimit -n, and keeps
its 10 ms backoff.

zig build test now runs the server's unit tests (zig/src/server/root.zig),
including a raise from a lowered soft limit and the once-per-burst rule.

Co-authored-by: plotarmordev <[email protected]>
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.

CUDA server silently stops accepting connections at the descriptor limit (default ulimit: ~600 idle connections)

2 participants