Repository navigation
Handle libevent 2.1.8's error callback from a failing connect; test on Rocky Linux 8 - #855
Conversation
libevent 2.1.8 and older run the bufferevent error callback from inside a failing bufferevent_socket_connect(), before it returns -1; 2.1.9 stopped doing that (1dde74ef). memtier handled the failure twice: handle_event() logged it and reconnected or ended the thread, freeing the bufferevent, and connect() then handled the -1 as well. On RHEL 8 (libevent 2.1.8) a full Unix socket listen queue (EAGAIN) crashed with SIGSEGV in bufferevent_disable() on the freed bufferevent, and a failed reconnect was counted twice. Both calls (connect() and the Unix socket backlog retry) now go through socket_connect(): while it is inside bufferevent_socket_connect(), handle_event() only records the error, and the caller handles the failure once, as with newer libevent. Deferred callbacks run later from the event loop and are unaffected. CI never ran libevent 2.1.8, the oldest release DEVELOPMENT.md lists as working: add a Rocky Linux 8 job (libevent 2.1.8, OpenSSL 1.1.1k, GCC 8, Redis 6.2) running make check and the standalone suite, plaintext and TLS. test_F16_ipv6 now skips where getaddrinfo() with AI_ADDRCONFIG, as evhttp resolves the bind address, rejects ::1 (e.g. a container without a non-loopback IPv6 address). On Rocky Linux 8 the standalone plaintext suite had 12 failures: 10 in test_unix_connect_backlog, 1 in test_cli_validation_reconnect_backoff and test_F16_ipv6. Those files now pass. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🤖 Automated first-pass review — a human maintainer's review is still required before merge. Thanks for this. The write-up of the 2.1.8
You already flagged that the cluster suite on 2.1.8 isn't covered. That's fine as a follow-up, I don't think it should block this. The core fix looks solid and small to me. I'd mainly like a maintainer to decide whether the Rocky job becomes required before this merges. |
- handle_event() returns early inside socket_connect() only for an error event; any other event is handled as usual, should a libevent ever deliver one synchronously. - The Windows path passes libevent no address, so libevent cannot fail that connect synchronously: say so instead of setting the guard. - Say "before 2.1.9" rather than "2.1.8 and older" (configure accepts 2.0.11), and describe RHEL 8's libevent in the CI comment without pointing at a DEVELOPMENT.md line that master does not have yet. - test_F16_ipv6: socket.gaierror is an OSError. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thanks. Pushed cb1cbe0:
Also from the reviews: the comments say "before 2.1.9", since configure accepts 2.0.11 and 2.0.x behaves like 2.1.8. The CI comment no longer cites a DEVELOPMENT.md line that only #823 adds. |
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thanks. Pushed 71ff40a:
|
|
Thanks.
|
Resolve the comment-only conflict in setup_event() by keeping both notes, and say in DEVELOPMENT.md that CI now runs 2.1.8 (test-rockylinux-8). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Keep both sides in shard_connection: #855's socket_connect members and NULL check, then this PR's read tracking. DEVELOPMENT.md (from #545 and #823) now says memtier reads past 2.1's 4 KiB cap on plaintext. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Fixes #856. When the Prometheus exporter could not resolve its bind address, the error ended in "Success": ``` error: prometheus exporter: failed to bind ::1:0: Success ``` `evhttp_bind_socket_with_handle()` resolves the address with `getaddrinfo()`. When that fails (for example `AI_ADDRCONFIG` rejecting `::1` on a host without a non-loopback IPv6 address), no socket error is set, so we printed errno 0. Changes, all in `prometheus_exporter::start()`: - Clear the socket error before the call. - Print the error only when it is non-zero. Otherwise print "address could not be resolved or used". - Bracket IPv6 addresses, using the same `find(':')` check as the "listening on" line. The message is now `failed to bind [::1]:0: address could not be resolved or used`, or `failed to bind [2001:db8::1]:0: Cannot assign requested address` on a host with IPv6. **Test:** `test_F16b_bind_failure_message` in `tests/test_prometheus.py` binds to `2001:db8::1`, a documentation address that is never local, so the bind fails on every host. On hosts without IPv6 it fails at `getaddrinfo()`, the path that printed "Success". On GitHub runners `bind()` fails with `EADDRNOTAVAIL`. The test checks for exit code 1, a bracketed address, and a message that doesn't end in "Success". It also tries `::1` and skips that case if `::1` binds. (A `.invalid` hostname can't be used, because `--prometheus-bind-addr` rejects hostnames while parsing options.) CI coverage: GitHub runners have IPv6, so in CI `2001:db8::1` fails at `bind()` and `::1` binds. CI therefore checks the brackets and the real `bind()` reason, but not the no-errno fallback. That path was verified in IPv6-less containers (below). Results (Ubuntu 24.04 container, libevent 2.1.12): - Master's `prometheus_exporter.cpp` with the new test fails 4 checks without IPv6, and fails the bracket check on an IPv6 Docker network. - With the fix, the test passes in both. `make check` passes. `test_prometheus.py` passes, apart from `test_F16_ipv6` in the IPv6-less container (fixed by #855). clang-format is clean. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Low Risk** > Startup-only error messaging and diagnostics; no change to metrics serving or bind behavior beyond clearer stderr output. > > **Overview** > Fixes misleading **"Success"** text when the Prometheus exporter cannot bind (#856). Before `evhttp_bind_socket_with_handle()`, the code now clears the libevent socket error so a stale errno is not reported. On failure it prints a **bracketed IPv6** address (matching the listen URL) and either the real socket error or **"address could not be resolved or used"** when `getaddrinfo()` fails without setting errno. > > Adds **`test_F16b_bind_failure_message`**, which binds to `2001:db8::1` (and optionally checks `::1` if bind fails) to assert exit code 1, bracketed addresses, and no trailing "Success". > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 1df3df7. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY --> Co-Authored-By: Claude Opus 5.5 <[email protected]>
Picks up 14 master commits, including the connect-failure changes in #855 (libevent 2.1.8's error callback from a failing connect), #823 (hardened libevent failures), #822 (TLS error reporting) and the libevent compatibility CI from #545. No conflicts. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Fixes the `Test Rocky Linux 8 (libevent 2.1.8, TLS=1)` job, which has failed on master since #855 landed (first failing run: 60ec3f0). `test_bufferevent_creation_failure_fails_connection` (from #823) always expected memtier to close the socket after `bufferevent_openssl_socket_new()` fails. On a real libevent 2.1.8 or older with TLS, memtier deliberately leaves that socket open, because libevent may already have closed it (`libevent_ssl_failure_socket_is_ours()`). The neighbouring `test_tls_bufferevent_failure_leaves_socket_on_libevent_2_1_8` checks exactly that with a faked version. #823 and #855 merged one after the other, so the real-2.1.8 TLS job never ran this test before landing. The test now reads the runtime libevent from `--version`. With TLS on libevent older than 2.1.9 it expects `left open on purpose` and the shim's `socket open` marker; otherwise it still expects `socket closed`. This is a test-only change, and memtier's behaviour is unchanged and correct. Results for `test_library_provenance.py`: - Rocky Linux 8 (libevent 2.1.8) with TLS: 7/7. - Ubuntu 24.04 (libevent 2.1.12), ASan + UBSan, plain and TLS: 7/7 each. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Low Risk** > Test-only change; memtier runtime behavior is unchanged and only assertions are version-aware. > > **Overview** > Fixes CI on **Rocky Linux 8** (real libevent 2.1.8 with TLS) by aligning `test_bufferevent_creation_failure_fails_connection` with memtier’s existing socket-handling rules. > > That test used to always require the preload shim’s **`socket closed`** marker after a forced `bufferevent_*_socket_new()` failure. With **TLS** and **libevent older than 2.1.9**, memtier intentionally leaves the fd open and logs **`left open on purpose: libevent …`** because libevent may have already closed it. The test now parses the runtime libevent version from `--version` and branches: TLS + < 2.1.9 expects the open-socket path; all other cases still expect **`socket closed`**. No application code changes. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 8e30c4f. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY --> Co-Authored-By: Claude Opus 5.5 <[email protected]>
Problem
RHEL 8 ships libevent 2.1.8, the oldest release memtier is known to work with. CI never ran it. Running the standalone suite on Rocky Linux 8 (libevent 2.1.8, OpenSSL 1.1.1k, GCC 8, Redis 6.2) gave 12 failures.
10 in
test_unix_connect_backlog, with SIGSEGV. libevent 2.1.8 runs the bufferevent error callback from inside a failingbufferevent_socket_connect()(freesock:callsbufferevent_run_eventcb_(bev, BEV_EVENT_ERROR, 0)), before it returns -1. 2.1.9 stopped doing that (1dde74ef, "bufferevent_socket_connect{,_hostname}() missing event callback and use ret code"). memtier therefore handled the failure twice:handle_event()loggedConnection error: Resource temporarily unavailable, then reconnected or ended the thread, which freed the bufferevent.connect()then handled the -1 itself. For a full Unix socket backlog (EAGAIN) that isbufferevent_disable(m_bev, ...)on the freed bufferevent:The Unix backlog retry (
handle_unix_connect_retry()) callsbufferevent_socket_connect()directly and had the same problem.1 in
test_cli_validation_reconnect_backoff. The same double handling counted a failed reconnect twice.test_F16_ipv6. This one is environmental. evhttp resolves the bind address withAI_ADDRCONFIG, which rejects::1in a container with no non-loopback IPv6 address. The skip guard only triedbind().Fix
socket_connect()wrapsbufferevent_socket_connect()for both callers. While it runs,handle_event()only records the error, and the caller handles the failure once, as with libevent 2.1.9 and newer. Deferred callbacks (BEV_OPT_DEFER_CALLBACKS, e.g. an immediate refusal) run later from the loop and are unaffected. The Windows path, which goes throughbufferevent_connect_nonblocking(), sets the same guard.test_F16_ipv6now also skips whengetaddrinfo("::1", AI_PASSIVE | AI_ADDRCONFIG)fails, which is the lookup evhttp makes.rockylinux:8container with the distro's libevent, OpenSSL and GCC, Redis 6.2 from AppStream, and Python 3.11. It checks--versionreportslibevent=2.1.8-stable, runsmake check, then runs the standalone suite.Testing
test_unix_connect_backlogalso passed 3 out of 3 repeated runs.test_unix_connect_backlog.py,test_cli_validation_reconnect_backoff.pyandtest_reconnections.pypass 51/51.make checkpasses without the fix. Consider making it required.Related: #823 documents 2.1.8 as the oldest known-working release ("CI does not build it yet"). This PR adds that CI job. Whichever of the two lands second updates that row.
🤖 Generated with Claude Code
Note
Medium Risk
Changes core connection setup in shard_connection for all POSIX connects; behavior is version-specific but affects reconnect/backlog paths on every platform.
Overview
Fixes double-handling of synchronous connect failures on libevent 2.1.8 (RHEL 8): when
bufferevent_socket_connect()fails, that release invokes the error callback before returning-1, which previously drove reconnect/teardown and then leftconnect()touching a freed bufferevent (SIGSEGV on Unix backlog retries and similar paths).socket_connect()wraps the libevent call and, while it runs,handle_event()only stashes the socket error inm_socket_connect_errorsoconnect()/handle_unix_connect_retry()handle the failure once, matching 2.1.9+ behavior. Comments noteBEV_OPT_DEFER_CALLBACKSis intentionally not used for this contract.Adds CI job
test-rockylinux-8(Rocky Linux 8, libevent 2.1.8, plaintext + TLS):make checkand the standalone integration suite. DEVELOPMENT.md documents that coverage.test_F16_ipv6skip guard now mirrors evhttp by probinggetaddrinfo("::1", …, AI_ADDRCONFIG), so IPv6 Prometheus tests skip in Docker without non-loopback IPv6.Reviewed by Cursor Bugbot for commit 63a43af. Bugbot is set up for automated code reviews on this repo. Configure here.