Skip to content

Build and run natively on Windows (MSYS2 / MinGW-w64) - #553

Merged
fcostaoliveira merged 30 commits into
redis:masterfrom
darth-modder:feat/windows-native
Oct 17, 2026
Merged

fcostaoliveira merged 30 commits into
redis:masterfrom
darth-modder:feat/windows-native

Conversation

@darth-modder

@darth-modder darth-modder commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Native Windows clients need WSL or another machine to run memtier because the build and runtime assume POSIX sockets, process facilities and time helpers.

Root cause

Winsock uses different socket handles, errors, initialization and nonblocking-connect behavior. UCRT also differs in CPU accounting, standard handles, file paths, binary I/O and integer widths.

Fix

Support native Windows10+ with MSYS2 UCRT64 and the existing autotools build. Use libevent socket types/helpers and Windows thread initialization; provide CPU/crash reporting and missing-library shims; reject unsupported Unix sockets. Preserve explicit AC_PROG_CC and the libtool-free build.

The Windows path starts nonblocking connect directly, then hands the socket to libevent. A synchronous WSAECONNREFUSED queues one connection-owned deferred error callback so existing reconnect policy applies. Disconnect/destruction cancels it; other immediate hard errors retain libevent's failure behavior. APIs remain compatible with the existing libevent2.0.10 floor. POSIX keeps its libevent path and Unix backlog retry timer.

Restore missing standard handles before opening outputs. Preserve POSIX Unix fixtures while using private TCP fixtures on Windows. All15 unit programs run on Windows. Crash timestamps use a UTC offset prepared before the exception filter; the fault path avoids localtime/strftime. Portable integer formatting/conversion changes support LLP64 without changing the reviewed LP64 behavior.

Current head 14a284c includes the normal merge of master b6e9d78 as 6f82fda, including meta protocol, Unix backlog retries, JSON fatal summaries and debug-only JSON lifecycle notices. Existing output/import validation, reconnect deadlines, completion policy and crash watchdog fixes remain present.

Tests and measured results

  • Current integrated head: all15 Linux unit programs pass. Independent BUILD confirms the JSON writer, logging consumers, build files and relevant finalization functions match the previously validated combined tree. No missing logging stub or new platform API was found.
  • Native Windows on prior head fa1e304: production build/warning gate, all15 units, version/hash checks and all10 smoke tests pass: https://github.com/redis/memtier_benchmark/actions/runs/39016446081 .
  • Integrated native Windows at 6f82fda passed the production warning gate,15 units and10 smoke tests: https://github.com/redis/memtier_benchmark/actions/runs/39018356290 . Final 14a284c only removes a stale documentation count; its exact-head native run also passed the production warning gate,15 units and10 smoke tests: https://github.com/redis/memtier_benchmark/actions/runs/39018544725 . Other cross-platform CI is pending.
  • Native smoke covers request counts, pipelines/reconnects, real TLS reconnect, CPU JSON, output errors, Unix rejection, connection refusal, absent standard handles, and a1024-byte monitor-input final line without LF. Six injected plain/TLS refusal cases verify callback dispatch, disconnect/destruction cancellation and socket closure; these are not claims of naturally reproduced Windows network failures.
  • Before the portability changes, current retry/deadline code failed native compilation because UCRT lacks timeradd/timersub. Libevent's equivalents compile and pass the native unit tests. Timestamp compilation guards reject the old localtime/strftime path and accept the arithmetic formatter; no CRT deadlock reproduction is claimed.
  • Independent lifetime/error-context checks include600 deferred-refusal and2000 diagnostic-path sanitizer cases. The latter are Linux runtime probes plus source analysis, not additional native Windows executions.
  • The warning gate covers production compilation. Unit compilation separately retains a known cluster_transaction_test signedness warning; the entire test build is not described as warning-free. No new throughput or cross-OS parity claim is made.

Affected versions

This is a new platform feature, not a regression in a released Windows build. No released-version introducer applies. MSVC and32-bit Windows are outside this implementation.

Limitations

Windows uses libevent's select backend, has coarse scheduler-accounted CPU samples, and does not support Unix sockets. Crash reporting is best effort for unhandled SEH exceptions and raw addresses, not abort/assert failures; fprintf/CRT stream locks can still prevent output. RLTest's POSIX signal and /proc cases remain outside native Windows CI. Full static/no-TLS native deployment is not claimed validated.

The rolling MSYS2 toolchain and blocking production warning gate intentionally expose new compiler diagnostics and can require maintenance on unrelated PRs. Repository branch protection is unchanged.


Note

High Risk
Large changes to networking, threading, crash handling, and startup paths on a new platform; POSIX behavior is mostly preserved but Windows-specific connect and error-deferral logic is security- and reliability-sensitive.

Overview
Adds native Windows 10+ builds with MSYS2 UCRT64 / MinGW-w64: new GitHub Actions workflow (warning-free build, make check, version hash check, tests/windows_smoke.py), developer docs, and .gitignore for *.exe.

Portability layer: new platform_compat.h consolidates Winsock vs POSIX networking includes; configure.ac detects MinGW, links ws2_32, sets Windows API macros, and skips libevent_pthreads on Windows. Call sites move to libevent socket/timer helpers (evutil_*), evthread_use_windows_threads(), and WSAStartup in main.

Runtime behavior on Windows: --unix-socket is rejected; CPU accounting uses GetThreadTimes(); crash reporting uses an SEH unhandled-exception filter (shared tail with POSIX) instead of alt-stack signal handlers; stdio fd reopening and output-prefix checks handle Win32 paths and detached CRT handles. Connections: nonblocking connect() bypasses libevent’s blocking getsockopt(SO_ERROR) path; synchronous WSAECONNREFUSED is deferred via a connection-owned libevent callback so reconnect policy matches POSIX. Shims add getline, jrand48, LLP64-safe strtoull parsing, and binary-mode file I/O.

Unit tests gain Windows TCP fixtures, Winsock startup, and injected refusal cases; RLTest result dirs sanitize : on NT.

Reviewed by Cursor Bugbot for commit 14a284c. Bugbot is set up for automated code reviews on this repo. Configure here.

🤖 Generated with Claude Code

@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

🤖 Automated first-pass review — a human maintainer's review is still required before merge.

Thanks for this, it's a big one. I read most of it, and the POSIX paths look carefully kept as they were. The commits are split well, which helps a lot. A few comments:

  • Blocking CI on a rolling toolchain. The workflow runs update: true on windows-latest and fails on any compiler warning outside deps/. The description already says this "can require maintenance on unrelated PRs". I wonder if we want that cost from day one. Did you consider making the warning gate non-blocking at first (continue-on-error, or a separate advisory step), and keeping only the build, make check and the smoke test as required? I'm not sure Linux contributors will be able to fix a new GCC diagnostic that only shows up on MSYS2.

  • Where the shims live. platform_compat.h is a good place for these, but the time shims are spread around. crash_report.h and retry_policy.cpp each add an inline #ifdef _WIN32 for localtime_s/gmtime_s, and crash_report_test.cpp defines its own gmtime_r/localtime_r/setenv wrappers. Would it be easy to put gmtime_r/localtime_r shims in platform_compat.h once, so callers stay unchanged? The same question applies to the getrusage shim in memtier_benchmark.cpp. The more #ifdefs in the main files, the more likely the next change breaks one platform without anyone noticing.

  • Fixes that affect every platform. The assert(0) return values, the %zu → %llu AUTH formatting and the strtoul → strtoull change in config_range all change code that Linux and macOS run too. I think they're correct and behave the same on LP64. Since they're independent of the port, though, they might go faster as a small separate PR, and this one would then be Windows-only. Not a blocker if it's easier to keep them here, since they're already separate commits.

  • Deferred WSAECONNREFUSED path. The connection-owned event, with cancellation in disconnect(), the destructor and setup_event(), looks right to me, and the injected tests cover all three teardown cases. One question: in bufferevent_connect_nonblocking(), is WSAEINVAL really safe to treat as "in progress" on a fresh socket? I know libevent counts it as retriable for connect, but it could also hide a real bad-argument error. I may be wrong here, and this may be worth a second look from someone who knows libevent's Windows backend well.

  • Nitpicking: retry_drain_test and reconnect_siblings_test now call set_address_port("127.0.0.1", "0") on POSIX too, where the Unix socket path is what actually gets used. It's harmless, but maybe keep it inside the _WIN32 branch so the POSIX fixture reads as it did before.

The description says native Windows validation for the current head is still pending. I'd want that run green, plus the full cross-platform CI, before this merges. I'd also like a maintainer to explicitly agree to support Windows long-term, since that's more of a project decision than a code question.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 133c58e. Configure here.

Comment thread shard_connection.cpp Resolved
@darth-modder

Copy link
Copy Markdown
Contributor Author

Pushed. I rebased onto the updated #552 and force-pushed, per CONTRIBUTING.

  • Scope: the JSON escaping is now Escape string values written to the JSON output #555, with a comment at the write_obj gate. This branch still carries it, because Windows paths need it.
    • The assert(0) returns and the strtoull change stay here, because the MinGW build needs them (MinGW's assert isn't noreturn, and strtoul is 32-bit there).
    • I can split those out as well if preferred.
  • Connect fallback: on an immediate failure that isn't "in progress", bufferevent_connect_nonblocking now returns -1 rather than calling bufferevent_socket_connect(bev, sa, len) again.
    • shard_connection::connect reads the error before disconnect(), so the log shows the original Winsock error.
    • The only synchronous failure I could trigger was port 0 (WSAEADDRNOTAVAIL). Other addresses return WSAEWOULDBLOCK.
    • With a fake CLUSTER SLOTS server advertising 127.0.0.1:0, memtier now exits in about 1 s with connect failed, error = The requested address is not valid in its context.
    • The in-progress path is unchanged.
  • CI: fine with making the Windows job non-required at first. That's your call.
  • Warning grep: it now matches only compiler diagnostics (^[^ ]+:[0-9]+:[0-9]+: warning:), with deps/ still excluded. libtool: warning: and make[1]: warning: no longer match.
  • DEVELOPMENT.md: the RLTest suite isn't run in CI on Windows. It can be run locally against Memurai with a small RLTest shim. The tests that can't pass on Windows are the crash-handler, SIGINT and SIGPIPE ones.

Re-tested:

  • Windows: zero warnings, make check 2/2, smoke 4/4. Against Memurai, the JSON, simple-flow, reconnection and Prometheus suites pass 70/71; the one failure is the SIGINT test.
  • Linux: no new warnings, and the JSON tests pass.

Several non-void functions (the unsupported-command stubs of the memcache
protocols and the mbulk/bulk element accessors) ended in `assert(0)` with
no return. Under NDEBUG the assert compiles away and control falls off the
end of a non-void function, which is undefined behaviour. Return an
explicit -1/false/NULL after each assert(0), and initialise `key_len` in
the multi-get loops so it is never read uninitialised.

Also pass the AUTH argument lengths to evbuffer_add_printf() as
`%llu` with an explicit `unsigned long long` cast instead of `%zu`:
MinGW checks evbuffer_add_printf() formats as ms_printf, which does not
know `%zu`. The bytes written are unchanged.
Detect a MinGW host in configure.ac and, there only: define
_WIN32_WINNT/WIN32_LEAN_AND_MEAN/NOMINMAX/__USE_MINGW_ANSI_STDIO, link
ws2_32, skip the libevent_pthreads check (libevent's Windows thread
backend lives in libevent_core), and default to static libraries so
libtool does not wrap the program in a launcher exe that loses the exit
status on Ctrl+C. Expose the result as the MEMTIER_WINDOWS automake
conditional.

In Makefile.am, skip socket_options_test on MinGW and give
prometheus_metrics_test the feature macro that makes mingw-w64 declare
rand_r(). Ignore *.exe and /.libs/ in .gitignore. No change for other
hosts.
Add platform_compat.h, which pulls in the Winsock/AF_UNIX headers on
Windows and the existing POSIX socket headers elsewhere, and use it in
place of the scattered <sys/socket.h>/<netdb.h>/<arpa/inet.h> includes.
Switch socket descriptors to evutil_socket_t and replace fcntl(O_NONBLOCK),
close() and errno-based socket error reporting with libevent's
evutil_make_socket_nonblocking(), evutil_closesocket() and
EVUTIL_SOCKET_ERROR()/evutil_socket_error_to_string(), which are plain
fcntl()/close()/errno/strerror() on POSIX. Cast setsockopt() option
pointers to const char * as Winsock requires, build struct timeval values
field by field, initialize Winsock with WSAStartup() and select libevent's
Windows thread backend in main().

Gate the remaining POSIX-only pieces behind _WIN32: the crash handler,
per-thread/rusage CPU accounting (reported as zero on Windows for now),
RLIMIT_NOFILE/core-dump handling, SIGPIPE, ucontext and utsname.
--unix-socket is rejected with an error on Windows, and --randomize
derives its seed without srandom()/random().

Other fixes: provide a getline() fallback for --monitor-input, open
import/export files in binary mode (identical to text mode on POSIX),
supply a jrand48() equivalent for the HAVE_DRAND48 code path when neither
random_r nor jrand48 exist, use gmtime_s(), and use hdr_timespec (a
typedef of struct timespec on POSIX) for the HDR log timestamps.

POSIX code paths are unchanged.
CPU accounting was compiled out on Windows (RUSAGE_THREAD is not defined
there) and the live sampler read 0 because winpthreads' pthread_getcpuclockid
is an ENOTSUP stub. Provide a file-local struct rusage / RUSAGE_THREAD /
getrusage() shim built on GetThreadTimes(GetCurrentThread()) so the existing
RUSAGE_THREAD blocks compile unchanged, drop the "&& !defined(_WIN32)" guards
they carried, and read other threads' CPU in get_thread_cpu_usec() with
GetThreadTimes() on the winpthreads handle. Update the comments that
described CPU accounting as Linux-only.

GetThreadTimes() is scheduler-tick accounted (~15.6 ms resolution), so very
short intervals read as zero; this is advisory data like on the other
platforms. POSIX code paths are unchanged.
The POSIX crash handler is compiled out on Windows. Install an unhandled
exception filter via SetUnhandledExceptionFilter() that prints the same
report: START banner, exception code, fault address (and the access
violation target), raw return addresses with the image base for addr2line,
then the INFO OUTPUT section with the Windows version and the CLIENT LIST.
It returns EXCEPTION_CONTINUE_SEARCH so Windows Error Reporting (LocalDumps)
still gets the crash, and the report points at LocalDumps instead of
ulimit/core_pattern.

The INFO OUTPUT / CLIENT LIST / footer part moves unchanged into
print_crash_report_tail(), shared by both handlers; the POSIX report text
is byte-for-byte the same. print_client_list() and
print_all_threads_stack_trace() are no longer POSIX-only.

abort() and assert() failures do not go through the exception filter and are
not covered.
Build with MSYS2 UCRT64 on windows-latest, failing on any compiler warning
outside deps/, then run make check, verify --version reports a real commit
hash and bits=64, and run tests/windows_smoke.py. The job has a 30 minute
timeout and refreshes the git index before building so version.sh does not
report a dirty tree.

The smoke test needs only the Python standard library: it drives
memtier_benchmark against the RESP sink in tests/fuzz and checks a
fixed-request-count run, the JSON CPU section of a timed run, a clean
non-crashing failure against a closed port, and the rejection of
--unix-socket.
Add a Windows (MSYS2 / MinGW-w64) section to DEVELOPMENT.md with the
package list, build commands, how to ship the executable (DLL list, or an
example static link recipe), the Windows 10 minimum, and the known
limitations of the Windows build. Point to it from the README's
build-from-source section.
The MinGW "default to static" tweak called AC_DISABLE_SHARED inside an
AS_CASE. Where libtool is not installed (the Debian CI containers install
only build-essential autoconf automake pkg-config libevent-dev zlib1g-dev
libssl-dev) that is an undefined AC_ macro, so autoreconf fails with
"possibly undefined macro: AC_DISABLE_SHARED". An undefined LT_INIT is
tolerated, an undefined AC_ macro is not.

Worse, with libtool installed, AC_DISABLE_SHARED expands LT_INIT inside the
mingw case branch, so on every other host libtool was left uninitialised
("whether to build shared libraries..." printed an empty result).

Pre-seed enable_shared=no on mingw instead, which LT_INIT's
--enable-shared handling honours. This needs no libtool macros, keeps
LT_INIT unconditional, and an explicit --enable-shared still wins.
config_range used strtoul(), whose result is 32 bits wide on LLP64 hosts
(Windows) and saturates for large input, while on LP64 hosts it is 64 bits and
narrows to int. --data-size-range=1-9999999999 therefore failed argument
validation on Windows (exit 2) instead of behaving as on Linux/macOS, which
test_426_8_data_size_range_too_large relies on. Parse with strtoull() so every
platform sees the same value; on LP64 hosts unsigned long and unsigned long
long are the same width, so behaviour there is unchanged.
…ories

RLTest test names look like "file.py:test_name" and RunConfig used the name
verbatim as a directory name; ':' is not allowed in Windows paths, so every
test that builds a RunConfig failed in ensure_clean_benchmark_folder() there.
Replace the reserved characters with '_'. Names on POSIX hosts that contain
none of them (which is every other character) are unaffected, but the
colon-containing RLTest names now map to "file.py_test_name".
On Windows, bufferevent_socket_connect() follows the expected
WSAEWOULDBLOCK from a non-blocking connect() with getsockopt(SO_ERROR)
(libevent's evutil_socket_geterror()). While the connect is still in
flight that call blocks for 10-15 ms, even on loopback. All connections
are opened one after another before the worker threads start, so setup
took about 15.6 ms * threads * clients: -t4 -c50 spent ~3.1 s connecting
and -t4 -c250 ~15.5 s, and every reconnect paid it again.

Issue the non-blocking connect() in shard_connection and pass libevent
the in-flight socket (a NULL address), which bufferevent_socket_connect()
documents as "assume the socket is already connecting". libevent then
arms the write event exactly as it does after its own WSAEWOULDBLOCK, so
completion, refusal and TLS handshakes are reported through the event
callback as before. connect() errors other than "in progress" are left
to libevent, which retries the connect and reports them as before.

The change is Windows-only; POSIX builds call bufferevent_socket_connect()
with the same arguments as before.
When the non-blocking connect() fails immediately with an error other than
"in progress", the Windows path used to call bufferevent_socket_connect()
with the address, which makes libevent issue connect() a second time on the
same socket, and Winsock is not guaranteed to report the original error for
that second call. Return -1 instead so the caller logs the error from the
failed connect().

The caller now reads the socket error before disconnect(), which frees the
bufferevent and could otherwise overwrite it.
The gate grepped build.log for the bare word "warning", which also matches
"libtool: warning: ..." lines and any path containing "warning". Match the
compiler diagnostic format ("file:line:col: warning:") instead; the deps/
exclusion is unchanged.
DEVELOPMENT.md claimed the suite had never been run on Windows. State what
is true: it is not run in CI there, it can be run locally against a Windows
Redis-compatible server such as Memurai with a small RLTest shim, and the
tests that need POSIX signals or /proc cannot pass.
The RLTest note listed the crash-handler and SIGPIPE tests, but the
SIGINT test (test_interrupt_signal_handling) also needs a POSIX signal, and
running against Memurai needs a shim for its --version output as well.
fcostaoliveira added a commit that referenced this pull request Oct 14, 2026
--hdr-file-prefix builds per-command file names from the display name, so
--scan-incremental-iteration writes "<prefix>_SCAN <cursor>_command_run_1.hgrm".
'<' and '>' are reserved file-name characters on Windows (fopen() fails
and the histogram is silently lost once the native build from #553 lands),
and actions/upload-artifact rejects them, so CI jobs cannot upload these
files.

Replace spaces, control characters and < > : " / \ | ? * with '_' in the
command part of the HDR file names. The prefix, the stderr messages, the
.hgrm header and the JSON keys keep the display name.

Sanitizing runs before the #587 duplicate-name pass, so names that map to
the same string (e.g. "A:" and "A?") still get distinct "_N" suffixes.
The suffix pass now also skips an ordinal whose label is already taken
by another name (e.g. a literal "A__1"), so a suffixed label can no
longer overwrite another command's file.

This changes user-visible file names: "SCAN <cursor>" becomes
SCAN__cursor_, "SCAN 0" becomes SCAN_0, and --command-stats-breakdown=line
names such as "GET (Line 1)" become GET_(Line_1).

Fixes #627

Co-Authored-By: Claude Opus 5.5 <[email protected]>
fcostaoliveira added a commit that referenced this pull request Oct 14, 2026
--hdr-file-prefix builds per-command file names from the display name, so
--scan-incremental-iteration writes "<prefix>_SCAN <cursor>_command_run_1.hgrm".
'<' and '>' are reserved file-name characters on Windows (fopen() fails
and the histogram is silently lost once the native build from #553 lands),
and actions/upload-artifact rejects them, so CI jobs cannot upload these
files.

Replace spaces, control characters and < > : " / \ | ? * with '_' in the
command part of the HDR file names. The prefix, the stderr messages, the
.hgrm header and the JSON keys keep the display name.

Sanitizing runs before the #587 duplicate-name pass, so names that map to
the same string (e.g. "A:" and "A?") still get distinct "_N" suffixes.
The suffix pass now also skips an ordinal whose label is already taken
by another name (e.g. a literal "A__1"), so a suffixed label can no
longer overwrite another command's file.

This changes user-visible file names: "SCAN <cursor>" becomes
SCAN__cursor_, "SCAN 0" becomes SCAN_0, and --command-stats-breakdown=line
names such as "GET (Line 1)" become GET_(Line_1).

Fixes #627

Co-authored-by: Claude Opus 5.5 <[email protected]>
@fcostaoliveira

Copy link
Copy Markdown
Collaborator

Addressed in eed9262 and the integration commits:

  • Windows standard descriptors: the -2 case now duplicates an opened NUL handle onto the allocated CRT descriptor with _dup2, instead of assuming open() returns that slot. Probing a genuinely closed descriptor uses a temporary thread-local invalid-parameter handler, restored before startup continues. A Windows-only smoke test starts memtier detached with all three standard handles absent and checks explicit text/JSON output plus exact server request counts. Its native CI rerun is pending.
  • The description has been rewritten around the current tree: no libtool, all 14 unit programs enabled, and current rather than historical validation counts. The old Bugbot-generated summary was removed with the stale body. The unconditional test names are now back in the main Makefile list.
  • The retry fixtures intentionally use private loopback TCP on every OS so the same retry/deadline assertions run everywhere. Their state-machine invariant does not depend on Unix addressing. The socket-options fixture retains the POSIX Unix connection path and three connect/disconnect cycles; it also runs IPv4/IPv6 and TLS setup on Windows. The new Windows hard-failure check covers port zero with and without TLS.
  • The CI fallback is a separate commit and is needed to run fork checks when the upstream repository variable is unavailable; the adjacent comment identifies SMOKE_TEST_IMAGES as the configured upstream matrix. It does not replace a defined variable.
  • No branch-protection policy was changed. This workflow adds coverage; making the new job a required branch-protection check is a separate repository policy decision.

Native Windows at 9b0997e passed the warning-free build, all 14 unit programs and all 8 smoke tests. The new detached-process case is being checked on eed9262. Linux controls pass all 14 units and 34 focused closed-fd/crash-handler/import regressions (the three valid-import cases used a local AUTH adapter for the private password-protected Redis).

@fcostaoliveira

Copy link
Copy Markdown
Collaborator

The follow-up is now at 8736d8b:

  • Preserved the original Unix-domain fixtures for both retry regressions on POSIX; Windows runs their TCP variants. All 14 unit programs remain enabled on both platforms. The Windows IPv6 skip paths now use Winsock error codes rather than errno.
  • Native fcdc4d2 passed the warning-free build, all 14 unit programs and all 9 smoke tests, including detached startup with absent standard handles and the closed-port error diagnostic. The temporary CRT invalid-parameter handler uses MinGW's available process-wide setter at single-threaded startup and restores it before creating workers. Final 8736d8b is a test-only follow-up with CI rerunning.
  • WSAEINVAL/WSAEINTR remain in the same retriable set libevent uses. The socket is freshly created, its sockaddr is from the selected address family, and a genuine immediate port-zero failure is tested with and without TLS. There is no reproduced valid-endpoint case supporting a different compatibility rule here; setup still has the existing supervisor/connection-timeout policy.
  • The platform-neutral pieces are already separate commits. They are needed by this native build (including MinGW format checking); splitting them into additional PRs would add dependencies without changing the final reviewed diff. The distro fallback is likewise a separate commit, with an adjacent comment identifying the upstream repository variable it supplements when fork contexts cannot read it.
  • No branch-protection requirement was changed. The added job supplies native coverage; future required-check/release support policy stays with repository maintainers. The merge is intended to be a squash, with its final description reflecting the resulting tree rather than intermediate commit states.
  • The Windows crash-report limitation is explicit: its shared helper retains the existing name, while Windows can only report the crashing thread's raw stack.

The PR body now lists these final behaviors and measured results. All historical Cursor threads are resolved.

@fcostaoliveira

Copy link
Copy Markdown
Collaborator

Addressed the crash timestamp point in 2c75aca: Windows caches g_crash_utc_offset before SetUnhandledExceptionFilter() and the filter calls the same arithmetic crash_format_time() as POSIX. It no longer calls localtime() or strftime() after the fault. POSIX prewarming and formatting stay unchanged. I verified the actual timestamp block with those two APIs compile-time-forbidden: the old block fails and the new block compiles and prints the expected timestamp. Existing timestamp arithmetic unit tests pass. This proves the source path; I am not claiming a reproduced UCRT lock deadlock or making the rest of the best-effort report lock-free.

The normal master merge includes #257 and preserves its exact Unix sockaddr length alongside Windows's connect wrapper. All 14 Linux unit programs and all five Unix address regressions pass. Help and the man page now label --unix-socket POSIX-only.

Native Windows on 8736d8b did pass all 14 unit programs (including retry drain/sibling tests) and all nine smoke tests: https://github.com/redis/memtier_benchmark/actions/runs/39013454099 . The new 2c75aca head is rerunning CI; the description now distinguishes those results.

The scope items remain in their separate commits within this port. The fallback matrix is now also on merged master through #257; its existing comment identifies the upstream repository variable, whose defined value takes precedence. Independent connection/reconnect reviews are in progress before any merge.

@fcostaoliveira

Copy link
Copy Markdown
Collaborator

Follow-up for the 07:34 and 07:47 edits, now at 972d454 (runtime 7cf8437):

The independent dispatch review found a narrower real compatibility bug: libevent returns success and defers an error event for synchronous ECONNREFUSED, while the Windows wrapper had returned -1. Fixed with a connection-owned event using event_new/event_active (available at the existing libevent 2.0.10 minimum). It delivers one deferred error with the original Winsock code, enters existing reconnect policy, and is canceled before disconnect/destruction or bufferevent replacement. TLS keeps the same owning bufferevent. There is no inline callback or second connect on the failed socket. EADDRNOTAVAIL/ENETUNREACH were checked separately: original libevent also returns -1 immediately for those, so that behavior remains unchanged.

Native Windows runtime 7cf8437 passed all 14 units and 9 smoke tests: https://github.com/redis/memtier_benchmark/actions/runs/39014863571 . The socket unit now injects synchronous WSAECONNREFUSED in six plain/TLS cases, checking normal dispatch, disconnect-before-dispatch, and destruction-before-dispatch, including error preservation, retry scheduling and socket closure. This is an injected dispatch/lifetime regression, not a claim of reproducing a natural Windows network failure. The earlier 2c75aca crash timestamp follow-up also passed native 14/9. The production compiler-warning gate passes; unit compilation separately still has an existing -Wsign-compare diagnostic, now qualified in the description.

972d454 adds the requested getline coverage: the native smoke reads a 1024-byte quoted monitor command with no final newline and completes three requests. It crosses several reallocations and covers EOF handling. That focused smoke passes on Linux; its native follow-up is running: https://github.com/redis/memtier_benchmark/actions/runs/39015091236 .

The platform policy remains explicit: native Windows10+ through MSYS2 UCRT64 is the implementation scope; no branch-protection settings or release promises changed. Maintainers own whether to require the job. I considered a larger platform_compat.cpp extraction, but kept this review to the existing focused portability changes; centralizing those implementations can be a separate cleanup. The generic fixes remain separate dependency commits within this port rather than introducing additional PR dependencies. Drive-relative C:hist preflight is a known narrow limitation; the actual output open/write error checks remain in force. The POSIX Unix fixtures still select their Unix socket despite the harmless TCP address initialization.

@fcostaoliveira

Copy link
Copy Markdown
Collaborator

For the 07:50:59 edit: the deferred callback owns the current bufferevent association for its whole queued lifetime: setup_event(), disconnect(), and destruction cancel it before replacing/freeing the bufferevent. The six native tests cover dispatch and both teardown paths with plain/TLS bufferevents, and the independent reconnect/lifetime reviewer is rechecking the exact runtime commit.

I considered pinning MSYS2 or removing the production warning gate. This job deliberately tracks the supported rolling UCRT64 environment so its dependency/compiler changes become visible; a pinned package snapshot would need a separate update policy. The 30-minute timeout is a cap, not the measured job duration (the last successful run took about 3.5 minutes). Required-check and release-support policy remain with maintainers; this PR does not alter them. Generic fixes remain separate dependency commits as described above.

The config_range narrowing remains the existing int conversion, so this is not new range validation. Also, --randomize is timestamp-seeded and already does not promise comparable seeds between runs or platforms; the Windows seed-generation path is different. I will leave these explanatory nits and reading EVUTIL_SOCKET_ERROR once to follow-up cleanup rather than change the runtime after the completed native dispatch validation.

@fcostaoliveira

Copy link
Copy Markdown
Collaborator

Follow-up to the review edited at 08:13:42 UTC, on final head fa1e304:

  • CI stability: the rolling MSYS2 UCRT64 toolchain and blocking production warning gate are intentional. A new compiler diagnostic may require maintenance even on an otherwise unrelated PR; pinning would defer that compatibility signal. We keep the gate blocking and document that cost. It scans production compilation, not the separately compiled units, where an existing signedness warning remains. This does not change branch protection.
  • Scope: the portable return values, AUTH formatting and config-range conversion are required by the MinGW/LLP64 build. They have independent BUILD/SEM review and LP64 controls. We are retaining them with the port rather than introducing prerequisite PRs at this stage. Their scope and compatibility implications are documented; the final merge is a squash.
  • Helper extraction and Makefile ordering: these are reasonable cleanup suggestions, but do not change the reviewed behavior. The explicit platform branches keep CRT startup-handle repair visible, and we are leaving the now-tested layout in this PR. There are now 15 units after merging the meta-protocol unit from master.
  • Crash report: agreed, it is best effort. Avoiding localtime/strftime removes those calls from the fault path, but fprintf and CRT locking can still prevent a report. The PR limitations now state this explicitly; no async-safety or guaranteed-output claim is intended.
  • Socket error context: an independent focused review inspected libevent 2.0.10, 2.1.12 and native CI's 2.1.13. bufferevent_get_openssl_error pops libevent's stored integer errors; it does not call OpenSSL or Winsock. Our bufferevents do not use BEV_OPT_THREADSAFE, so the optional lock path makes no external call either. ERR_reason_error_string is called only after ssl_error=true, which suppresses the later plain socket diagnostic. Thus the proposed overwrite is not present in this path. An extracted production-block probe preserved ECONNREFUSED and the complete diagnostic in 2,000 Linux ASan/LSan/UBSan cases (plain and TLS); that is supplemental Linux evidence, not a new Windows runtime claim. Source: https://github.com/libevent/libevent/blob/release-2.1.13-stable/bufferevent_openssl.c .

The owner pass and all seven independent review lenses have converged, including focused checks of both master integrations. Exact-head native Windows CI passed production compilation, 15/15 units and 10/10 smoke tests: https://github.com/redis/memtier_benchmark/actions/runs/39016446081 . Full cross-platform CI is still required before merge.

@fcostaoliveira

Copy link
Copy Markdown
Collaborator

Reply to the review edited at08:43:56 UTC:

  • Removed the hardcoded unit count from DEVELOPMENT.md in 14a284c; make check now says it runs all unit programs. This is the only change after the current-master integration.
  • The CI policy decision is to retain the rolling UCRT64 toolchain and blocking production warning gate. New compiler diagnostics are an intentional maintenance signal for this new supported build. We accept the documented maintenance cost; this PR does not change which checks branch protection requires. Unit compilation is separate and retains the previously identified signedness warning.
  • The connection state machine has received independent LIFE review and focused follow-ups. The deferred event is released and its member cleared before normal event dispatch; cancellation is idempotent during setup replacement/disconnect/destruction, and the callback does not access the connection after returning from event handling. Six native plain/TLS dispatch/cancellation cases and600 supplemental sanitizer cases cover the reviewed path. The normal reconnect scheduler remains responsible for subsequent attempts. No new blocker was found in that second review.
  • We considered centralizing the time/fd shims. The existing locations are retained to avoid a broader compatibility-header refactor in this port; the explicit boundaries and test-only shims have BUILD/LIFE coverage. Extracting them remains a reasonable cleanup, not required for the observed behavior.
  • The portable returns, AUTH formatting and wide conversion are needed to build the LLP64/MinGW target and were independently reviewed. They remain with the platform addition under the required squash workflow; we are not creating prerequisite PRs merely to preserve their intermediate commit boundaries.
  • The Makefile ordering is cosmetic and left unchanged. The ignored legacy .libs directory is harmless for old build artifacts and does not restore libtool or a link dependency.

After #25 merged, we normally integrated masterb6e9d78 as6f82fda. All15 Linux units pass, and integrated native Windows run39018356290 passed the production warning gate,15/15 units and10/10 smoke tests: https://github.com/redis/memtier_benchmark/actions/runs/39018356290 . The final documentation-only head has an identical build/runtime/test tree and its own CI is running. All seven review lenses have converged, with the focused BUILD integration check; final-head full CI and fresh bot/thread gates remain required before squash merge.

@fcostaoliveira

Copy link
Copy Markdown
Collaborator

Follow-up to the 08:46:36 review edit:

WSAEINVAL deliberately follows libevent's existing Windows connect classification: EVUTIL_ERR_CONNECT_RETRIABLE includes it, and evutil_socket_connect_ applies that classification to the first connect on a newly created socket too. See libevent's definition and connect implementation. This preserves the upstream classification; it is not a claim that every WSAEINVAL proves a successful pending connection. Later socket/event handling and the existing setup timeout still determine the outcome. Tightening that shared compatibility rule is outside this port.

The POSIX fixture continues to select its configured Unix socket; the address fields provide the Windows TCP fallback and are harmless on POSIX. The retained Unix address/path tests and independent integration checks pass. We are leaving this cosmetic fixture suggestion unchanged.

The scoped platform/CI decision remains native Windows 10+ with MSYS2 UCRT64, the production warning gate, unit tests and smoke coverage described above. This accepts the rolling-toolchain maintenance cost within the authorized merge workflow; it does not claim an additional human maintainer endorsement or change branch protection. Full RLTest remains POSIX-only.

Exact final head 14a284c now passes native Windows CI: production build/warning gate, 15/15 unit programs and 10/10 smoke tests, run39018544725. The known unit-only signedness warning is unchanged. Remaining cross-platform CI must pass before merging.

@fcostaoliveira
fcostaoliveira merged commit cae16bf into redis:master Oct 17, 2026
132 checks passed
fcostaoliveira added a commit that referenced this pull request Oct 24, 2026
A worker delayed inside a callback could arm its final reconnect before
the --test-time deadline: next_reconnect_delay() subtracted a fresh
wall-clock sample from the deadline, while event_add() counts from
libevent's cached loop time. If that early retry completed a
never-started client's setup, the client ran a whole extra interval (a
3 s run reported 6 s and exited 0).

Compute the remaining delay from event_base_gettimeofday_cached(), the
origin event_add() uses, falling back to gettimeofday() only on an API
error. libevent 2.0.10 returns monotonic uptime through that call, so
require 2.0.11 (core, OpenSSL and pthreads) and say so in the docs.

Building against the real 2.0.11 minimum exposed two #553 details: the
connect address pointer stays mutable for the older evutil API, and the
unit test compares sockets against static_cast<evutil_socket_t>(-1)
rather than EVUTIL_INVALID_SOCKET.

Fixes #811

Co-Authored-By: Claude Opus 5.5 <[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.

2 participants