Repository navigation
Retry full Unix socket listen queues without blocking the event loop - #258
Conversation
2a27e54 to
7ff52af
Compare
|
🤖 Automated first-pass review — a human maintainer's review is still required before merge. Thanks for this, and for carrying it forward after #257. Retrying on a timer instead of looping inline seems like the right shape. Keeping the original connection timeout armed across retries, and not charging
The core fix looks solid. I'd mainly like the refused-connect case above confirmed (or covered by a test) before this merges. (would file this as a comment, not a formal block) |
|
Addressed in dea97a2, on current master plus #257:
Final local validation: 14/14 unit tests, 10/10 backlog cases through RLTest in plaintext and 10/10 with TLS. The address-length interaction is covered for short and 107-byte abstract names; #257 should land first. Full independent reviews and fresh CI remain required before merge. |
|
Rechecked the edited 06:18:43Z review:
The latest commit changes only that README underline; the validated runtime remains dea97a2. Fresh final-head CI and the seven independent #258 reviews still gate merge. |
|
Follow-up on the latest review:
|
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
Reviewed by Cursor Bugbot for commit 58a4789. Configure here.
|
Confirmed the distinct retained-path refusal case independently. The fixtures first fill the real Unix queue until EAGAIN, then close the listener without unlinking its pathname; a raw connect confirms ECONNREFUSED. All16 final-head/sanitizer process cases pass across plaintext/TLS and startup/established finite/unlimited retry policies, with exact error/reconnect counts, no extra TLS errors and no hang or spin (maximum3.044s and0.0243CPU cores). A separate ASan/LSan/UBSan probe repeated the actual timer sequence800times: plaintext/TLS × restoring READ|WRITE/restoring the saved WRITE mask. Every case produced exactly one deferred error, zero TLS handshake starts, zero TLS error entries and zero residual events. libevent’s TLS enable path schedules event monitoring; it does not synchronously start a handshake here. The queued failure then reaches the existing cleanup/reconnect handler. The bot’s description of libevent returning0 for a scheduled refusal is correct; it did not produce an unsafe success path. Restoring the old mask made no observable difference in this case, so I kept the reviewed implementation instead of adding state without a demonstrated need. The earlier ENOENT control alone was insufficient; this followup explicitly covers ECONNREFUSED. A generic TLS “Operation not supported” diagnostic is also present in direct refusals that never enter backlog handling, and is separate from this change. The README’s long line is a wrapping nit and does not change its documented policy. The normal master merge49be62a resolves the post-#257 conflicts. Independent comparison confirms all production/test/doc entries match the previously tested combined tree; the sole difference is the already-approved CI fallback. All seven approvals and focused callback/refusal checks converge; fresh CI remains required. |

Problem
On Linux, a full Unix socket listen queue makes a nonblocking connect return
EAGAIN. Memtier currently aborts preparation even if the server starts accepting a fraction of a second later. The original reproduction in this PR used a Redis Unix listener with a small backlog and many clients.This branch includes #257's abstract Unix socket support for interaction coverage. Merge #257 first. Both filesystem and abstract addresses now recover from temporary listener backpressure.
Root cause
bufferevent_socket_connect()reports this Unix condition as a synchronous failure; unlike TCPEINPROGRESS, no connect is pending in the kernel. Repeating the call inline prevents the worker loop, connection timers and supervisor from running. The original PR loop consumed 0.504 CPU seconds during a 0.5-second backlog wait and spun until a four-second harness kill when the queue never drained.Fix
Retry the same pending Unix connect on a 10 ms libevent timer. Disable the bufferevent while waiting so TLS does not busy-poll its handshake on an unconnected socket, then restore events after the connect starts. Reuse the exact stored address length, including short abstract socket names. Free the timer on success, a terminal error, disconnect and destruction.
A full queue does not consume reconnect attempts. The original connection timeout remains armed across all retries, and the setup-stage timeout and interruption remain effective. Other errors use the normal reconnect policy. Once a connection reaches steady state, with
--reconnect-on-errorand unlimited reconnect attempts,--test-timealso stops an unsuccessful backlog wait at the existing #666 run deadline. Before any connection reaches steady state, the connection/setup-stage limits bound startup; disabling both permits waiting for the listener. Finite reconnect limits retain their existing policy. A debug message records the start of each backlog wait once, rather than every timer tick. No new options or output schema fields.Tests
bc8e316: a deterministic full listen queue aborts immediately with exit 1/EAGAIN; all four filesystem recovery/deadline/interrupt assertions fail on that baseline.7ff52af: delayed acceptance succeeds, but an indefinitely full queue consumes about four CPU seconds during a four-second timeout.make -j4 checkpasses 14/14. RLTesttest_unix_connect_backlog.pypasses 10/10 in plaintext and 10/10 with TLS. Covers filesystem recovery, connection timeout, setup-stage timeout and SIGINT; short and maximum-length abstract names; abstract reconnect intervals, exhausted reconnect attempts and the run deadline. Successful recovery checks exact JSON operation counts. The timeout case checks JSON CPU usage to catch TLS handshake spinning.All fixtures use private Unix names and dummy authentication. Linux-specific backlog tests skip on other platforms. CI and the independent review lenses still gate merging.
Affected versions
The synchronous failure path was introduced by the bufferevent conversion in
e22a4eadd83ff72537d2c13bc10658334b863d98, first released in 1.3.0, and remains in releases through 2.5.2 and masterbc8e316. The actual reproductions above cover current master and the original PR head. Older releases used a different raw-connect path and were not runtime-tested here. The abstract-socket cases apply to the new support in #257.Co-Authored-By: Claude Opus 5.5 [email protected]
Note
Medium Risk
Changes Unix/TLS connect startup and timer lifecycle in the hot connection path; behavior is well-tested but affects when benchmarks fail vs wait.
Overview
Fixes immediate connect failure when a Unix (or abstract Unix) listener’s accept queue is full:
EAGAIN/EWOULDBLOCKfrombufferevent_socket_connect()is now treated as a pending connect, not a fatal error.shard_connectionarms a 10 ms libevent timer to retry the same connect without blocking the worker loop. While waiting, the bufferevent is disabled so TLS does not spin on handshake I/O on an unconnected socket. Queue-full retries do not increment--max-reconnect-attempts; the original--connection-timeouttimer stays armed across retries. At--test-timedeadline (with unlimited reconnects), backlog waits stop like other late connects. Other errors still use normal reconnect/disconnect paths.--debuglogs once per attempt when the queue is full.README documents listen-queue behavior and how it interacts with connection/stage timeouts.
tests/test_unix_connect_backlog.py(Linux) exercises filesystem and abstract sockets, plaintext and TLS: recovery after the queue drains, connection/stage timeouts, SIGINT, reconnect limits, and run deadline with saturated queue after first SET.Reviewed by Cursor Bugbot for commit 49be62a. Bugbot is set up for automated code reviews on this repo. Configure here.
CI compatibility: fork PRs can receive an empty
vars.SMOKE_TEST_IMAGES; that prevented the distro matrix from being created while all visible jobs passed. The workflow now falls back to the same seven images currently configured upstream. An explicit repository variable still takes precedence. Independent focused build review and actionlint pass; fresh matrix execution is required.🤖 Generated with Claude Code