Skip to content

Fix data race in welcome_response() via localtime() - #13

Merged
mattsva merged 1 commit into
mnet-web:mainfrom
mattsva:fix/localtime-data-race
Oct 11, 2026
Merged

mattsva merged 1 commit into
mnet-web:mainfrom
mattsva:fix/localtime-data-race

Conversation

@mattsva

@mattsva mattsva commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Fixes #7.

welcome_response() calls localtime() from worker threads — not reentrant, it mutates a static struct tm shared process-wide. Confirmed under ThreadSanitizer (data race via tzset_internal). Fixed with localtime_r() / localtime_s() (Windows).

Tests: test/test_reentrancy.c — 32 concurrent welcome-page requests; reported the race under TSan before the fix, clean after. Wired into Make, CMake, Meson and CI.

Stacked on the previous PR in the series; merge in order.

@mattsva
mattsva force-pushed the fix/localtime-data-race branch from d93c3b7 to c251685 Compare October 9, 2026 16:55
@mattsva mattsva closed this Oct 9, 2026
@mattsva mattsva reopened this Oct 9, 2026
welcome_response() runs on worker threads and called localtime(), which
is not reentrant: it mutates a static struct tm shared process-wide.
Confirmed under ThreadSanitizer (data race via tzset_internal). Replaced
with localtime_r() on POSIX and localtime_s() on Windows.

Regression test: test/test_reentrancy.c runs 32 concurrent welcome-page
requests; it reported the race under TSan before the fix and is clean
after. Wired into Make, CMake, Meson and CI.

The new test binds port 18780, not 18779: meson runs its tests in
parallel and test_security already binds 18779, so the two collide.
@mattsva
mattsva force-pushed the fix/localtime-data-race branch from fd6447d to a6df887 Compare October 11, 2026 13:37
@mattsva
mattsva merged commit dd5150e into mnet-web:main Oct 11, 2026
8 checks passed
This was referenced Oct 11, 2026
@mattsva
mattsva deleted the fix/localtime-data-race branch October 11, 2026 14:10
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.

Data race in welcome_response() via localtime()

1 participant