fix: prevent infinite drain loop in forked BGSave child process#894
Open
eliastam wants to merge 2 commits intovalkey-io:mainfrom
Open
fix: prevent infinite drain loop in forked BGSave child process#894eliastam wants to merge 2 commits intovalkey-io:mainfrom
eliastam wants to merge 2 commits intovalkey-io:mainfrom
Conversation
bd3d3b6 to
8bce6fe
Compare
DrainMutationQueue spins forever in the BGSave forked child process because the mutation queue is a frozen snapshot that will never be drained by writer threads. Check VALKEYMODULE_CTX_FLAGS_IS_CHILD and return an error instead of attempting to drain. Also adds a configurable timeout (drain-mutation-queue-timeout-ms, default 5s) to DrainMutationQueue as a safety net, and an integration test covering the BGSAVE with non-empty mutation queue scenario. Signed-off-by: Elias Tamraz <tamrazelias@gmail.com>
8bce6fe to
4eb7371
Compare
otherscase
reviewed
Mar 12, 2026
src/index_schema.cc
Outdated
| static const auto max_sleep = std::chrono::milliseconds(100); | ||
| auto sleep_duration = std::chrono::milliseconds(1); | ||
| auto timeout = std::chrono::milliseconds( | ||
| options::GetDrainMutationQueueTimeoutMs().GetValue()); |
Collaborator
There was a problem hiding this comment.
GetDrainMutationQueueOnSaveTimeoutMs?
otherscase
reviewed
Mar 12, 2026
src/index_schema.cc
Outdated
| if (options::GetDrainMutationQueueOnSave().GetValue()) { | ||
| int flags = ValkeyModule_GetContextFlags(nullptr); | ||
| bool is_bgsave = (flags & VALKEYMODULE_CTX_FLAGS_IS_CHILD) != 0; | ||
| if (is_bgsave) { |
Collaborator
There was a problem hiding this comment.
We should still continue if the queue is empty at this point.
otherscase
reviewed
Mar 12, 2026
src/index_schema.cc
Outdated
Comment on lines
+1690
to
+1695
| auto status = DrainMutationQueue(ctx); | ||
| if (!status.ok()) { | ||
| VMSDK_LOG(WARNING, ctx) | ||
| << "Failed to drain mutation queue on load for index " | ||
| << vmsdk::config::RedactIfNeeded(name_) << ": " << status; | ||
| } |
Collaborator
There was a problem hiding this comment.
Timeout should only apply for save. We should keep the load behaviour unchanged.
Collaborator
Author
There was a problem hiding this comment.
reverted this change
cf417ac to
51f5cbc
Compare
- Rename config to drain-mutation-queue-on-save-timeout-ms - Only error in forked child if mutation queue is non-empty - Keep load behavior unchanged, timeout only applies to save Signed-off-by: Elias Tamraz <tamrazelias@gmail.com>
51f5cbc to
1d1acc6
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.
DrainMutationQueue spins forever in the BGSave forked child process because the mutation queue is a frozen snapshot that will never be drained by writer threads. Check VALKEYMODULE_CTX_FLAGS_IS_CHILD and return an error instead of attempting to drain.
Also adds a configurable timeout (drain-mutation-queue-timeout-ms, default 5s) to DrainMutationQueue as a safety net, and an integration test covering the BGSAVE with non-empty mutation queue scenario.