Repository navigation
TCP.listen's backlog is 512, not 16: a burst of 10k connections is answered in full - #977
Conversation
…swered in full A backlog of 16 is the accept queue's depth: once 16 handshakes wait for TCP.accept the kernel drops further SYNs and the clients retransmit after 1 s, then 3 s -- not refused, silently delayed, and under a burst many time out before the server reaches them. Measured with demos/io_http_server built from this tree, 10,000 connections opened at once each sending one GET, 10 s window: backlog 16 answers 9,920 with 80 timeouts, last answer at 6.51 s; 512 answers all 10,000, last at 2.37 s (SOMAXCONN, 4096 here, also answered all 10,000, last at 3.39 s). ss -ltn shows the listener's Send-Q go from 16 to 512. 512 in both lanes, the value Bun uses (Node uses 511): the same number everywhere, and the kernel caps it at its own limit (net.core.somaxconn, kern.ipc.somaxconn). tests/io/tcp_listen_backlog.bend listens and connects 32 times without accepting: all complete at once and it prints its line in the check, interpreted, JS and C lanes; with the released 2.0.22 runtime (listen 16) the eighteenth connect stalls on retransmits and the test hangs, so a regression shows as a hang, never as a wrong line. tcp_listen_close, tcp_loopback, tcp_poll, tcp_spawn, tcp_short_recv, tcp_send_slow_peer, tcp_connect_black_hole and port_bound keep their output on all four lanes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
3661148 to
3188cdb
Compare
|
Thanks, that's simpler and better: one number in both lanes, the same behaviour everywhere up to the platform's cap. Done in 3188cdb: I re-measured the burst with
So 512 loses nothing here. |
| close(fd); | ||
| return EINVAL; | ||
| } | ||
| // 512 in both lanes, as Bun and Node use; the kernel caps it at its own |
There was a problem hiding this comment.
| // 512 in both lanes, as Bun and Node use; the kernel caps it at its own |
these comments don't really add anything
| return io_fail(22); | ||
| } | ||
| if (sys.bind(fd, sys.ptr(at), 16) < 0 || sys.listen(fd, 16) < 0 | ||
| // 512, as in tcp_listen.c: the kernel caps it at its own limit. |
There was a problem hiding this comment.
| // 512, as in tcp_listen.c: the kernel caps it at its own limit. |
Asked in review. The commit message above keeps the reason: the same number in both lanes, capped by the kernel at its own limit. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Removed both in 7815ac2. The commit message still says why 512 (the same number in both lanes, capped by the kernel). |
nicolas-abril
left a comment
There was a problem hiding this comment.
Thanks, both points addressed. Merged onto current main: tcp_listen_backlog passes on the check, interpreted, JS and C lanes, and with listen(fd, 16) restored it times out as intended; the other tcp_/udp_ tests and port_bound still pass.
Canon fixed U02 (backlog 512, bendlang#977), U04 (Nat.min/max through the tail cycle loop, bendlang#1061) and U22 (the boxed Bool reaching Bool.or, bendlang#1038); U08 and U21 answer in C now, U20 in interp and JS. Still REPRO: U01, U03/U03t, U06, U10, U11, U14 spawn_sleep, U16-U19, U20 (C), U21 (interp, JS), and F01-F11 -- F01, no wall clock: IO.now is still monotonic. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01S4szbK155RvUkyET5spFdw
What changes
bend2/effs/tcp_listen.candbend2/effs/tcp_listen.jscalllisten(fd, 512)instead oflisten(fd, 16): the same number in bothlanes, the value Bun uses (Node uses 511). The kernel caps the backlog at
its own limit (
net.core.somaxconnon Linux, 4096 by default;kern.ipc.somaxconnon macOS, 128), so on every platform the accept queueis 512 or as deep as the system allows.
(Revised after review: the first version used
SOMAXCONNin C and theplatform's value in JS; one constant gives the same behaviour in both
lanes.)
A new test,
tests/io/tcp_listen_backlog.bend, listens and then connects32 times in a row without ever accepting: with a backlog of 16 the
eighteenth SYN is dropped and that connect stalls on retransmits, so a
regression shows as a hang rather than a wrong line; with 512 all 32
complete at once and the test prints its
#|line.Why
A backlog of 16 is the accept queue's depth. Once 16 handshakes are
waiting for
TCP.accept, the kernel drops further SYNs and the clientsretransmit after 1 s, then 3 s -- the connection is not refused, it is
silently delayed, and under a burst many of them time out on the client's
side before the server gets to them.
Measured with
demos/io_http_serverbuilt from this tree once with eachbacklog, on one 4-core Linux machine: 10,000 connections opened at once,
each sending one
GET /, 10 s window, one run each:SOMAXCONN(4096, the first version)ss -ltnshows the listener'sSend-Qgo from 16 to 512.Test output
tests/io/tcp_listen_backlog.bend, all four lanes on this tree(
bun bend2/main.ts <file> [--check-only | -o x.js | -o x]):Negative check: the same test run with the released
bend2.0.22, whoseruntime still has
listen(fd, 16), hangs (killed bytimeout 25, nooutput) -- the eighteenth connect never completes.
The existing
tests/io/tcp_listen_close,tcp_loopback,tcp_poll,tcp_spawn,tcp_short_recv,tcp_send_slow_peer,tcp_connect_black_holeandport_boundprint their expected lines onthe check, interpreted, JS and C lanes of this tree. The cluster-backed
gates/harness is not available in this environment; the test filefollows the
tests/<ns>/[a-z0-9_]+.bendrule and is well under the tokenceiling.
Duplicate check
No open or closed issue or PR in
bendlang/bendmentionsbacklog,SOMAXCONNor the listen depth;WONTFIX.txtdoes not cover it.