Repository navigation
Fix data race in welcome_response() via localtime() - #13
Merged
Merged
Conversation
mattsva
force-pushed
the
fix/localtime-data-race
branch
from
October 9, 2026 16:55
d93c3b7 to
c251685
Compare
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
force-pushed
the
fix/localtime-data-race
branch
from
October 11, 2026 13:37
fd6447d to
a6df887
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #7.
welcome_response()callslocaltime()from worker threads — not reentrant, it mutates a staticstruct tmshared process-wide. Confirmed under ThreadSanitizer (data race viatzset_internal). Fixed withlocaltime_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.