Drain LibMR threads to a safe point before fork() (MOD-15307)#97
Draft
gabsow wants to merge 1 commit into
Draft
Conversation
Add MR_DrainForFork()/MR_ResumeAfterFork(). On the main thread (from the module's FORK_CHILD_PRE handler) park the event-loop thread at a between-tasks safe point via a posted task and bounded-wait the worker pool to idle, so no LibMR thread holds a libc lock at fork() (ghost-lock). Bounded + fail-open; cooperative (not the SIGUSR2 mr_thpool_pause, which can freeze a worker mid-malloc). Resume releases the parked event-loop thread. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Summary
Adds
MR_DrainForFork()/MR_ResumeAfterFork(). Called from the embedding module's pre-fork handler (main thread),MR_DrainForFork():so no LibMR thread holds a libc lock at
fork()(which would ghost-lock the child).MR_ResumeAfterFork()releases the parked event-loop thread (called after the fork, on success or cancel).Cooperative, bounded, fail-open. Deliberately not the existing
mr_thpool_pause(SIGUSR2), which can freeze a worker mid-mallocholding the arena lock — exactly the ghost-lock this prevents. A worker still blocked acquiring the GIL is already malloc-safe, so a drain timeout there is benign.Why / depends on
Fixes the RedisTimeSeries ASM-migration nightly hangs (MOD-14615 valgrind, MOD-14239 sanitizer). The embedding module wires this to redis core's new
FORK_CHILD_PREsubevent (redis/redis#15327).Pre-merge note
The two
RedisModule_Log(..., "notice", ...)lines inMR_DrainForFork/MR_ResumeAfterForkshould be downgraded todebug(kept atnoticeto confirm the drain fires during CI validation).🤖 Generated with Claude Code