Fix valkey-benchmark hanging in single-thread duration mode#3079
Merged
zuiderkwast merged 2 commits intoJan 20, 2026
Conversation
Signed-off-by: yzc-yzc <96833212+yzc-yzc@users.noreply.github.com>
Contributor
Author
|
One way to reliably trigger this bug is to add the following code in /* Initialize request when nothing was written. */
if (c->written == 0) {
// DEBUG: Force duration to expire
static bool flag = true;
if (flag) {
config.start -= 1000; // Simulate 1 second has passed
flag = false;
}
int requests_issued = atomic_fetch_add_explicit(...);
if (isBenchmarkFinished(requests_issued)) {
c->pending = 0;
return;
}
...
}Then test with |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## unstable #3079 +/- ##
============================================
- Coverage 74.33% 74.30% -0.04%
============================================
Files 129 129
Lines 71009 71009
============================================
- Hits 52784 52762 -22
- Misses 18225 18247 +22
🚀 New features to boost your workflow:
|
Signed-off-by: yzc-yzc <96833212+yzc-yzc@users.noreply.github.com>
zuiderkwast
approved these changes
Jan 20, 2026
zuiderkwast
left a comment
Contributor
There was a problem hiding this comment.
LGTM, thanks.
@rainsupreme PTAL.
sarthakaggarwal97
approved these changes
Jan 20, 2026
sarthakaggarwal97
left a comment
Contributor
There was a problem hiding this comment.
Thank you! This will help daily CI run green.
rainsupreme
approved these changes
Jan 20, 2026
rainsupreme
left a comment
Contributor
There was a problem hiding this comment.
haha wow I didn't see that earlier! good catch 👍
arshidkv12
pushed a commit
to arshidkv12/valkey
that referenced
this pull request
Jan 23, 2026
…o#3079) In single-thread mode with --duration, the benchmark could hang indefinitely after the duration elapsed. ## Root Cause Consider the following scenario: **Step 1** (T = 0.99s, duration = 1s): - `readHandler` receives response, calls `clientDone()` - `isBenchmarkFinished()` returns `false` (0.99s < 1s) - `clientDone()` calls `resetClient()` **Step 2** (T = 1.01s): - `writeHandler` is called - `isBenchmarkFinished()` returns `true` (1.01s >= 1s) - `writeHandler` returns early, **no request sent, no read event registered** **Result**: - `readHandler` never triggers → `clientDone()` never called → no `aeStop()` - `showThroughput()` checks `num_threads && isBenchmarkFinished()`, skipping single-thread mode - **Event loop never terminates** Fixes valkey-io#2893, fixes valkey-io#2843 --------- Signed-off-by: yzc-yzc <96833212+yzc-yzc@users.noreply.github.com> Signed-off-by: arshidkv12 <arshidkv12@gmail.com>
Contributor
|
#2581 was not included in 9.0 so we should not backport this fix. |
harrylin98
pushed a commit
to harrylin98/valkey_forked
that referenced
this pull request
Feb 19, 2026
…o#3079) In single-thread mode with --duration, the benchmark could hang indefinitely after the duration elapsed. ## Root Cause Consider the following scenario: **Step 1** (T = 0.99s, duration = 1s): - `readHandler` receives response, calls `clientDone()` - `isBenchmarkFinished()` returns `false` (0.99s < 1s) - `clientDone()` calls `resetClient()` **Step 2** (T = 1.01s): - `writeHandler` is called - `isBenchmarkFinished()` returns `true` (1.01s >= 1s) - `writeHandler` returns early, **no request sent, no read event registered** **Result**: - `readHandler` never triggers → `clientDone()` never called → no `aeStop()` - `showThroughput()` checks `num_threads && isBenchmarkFinished()`, skipping single-thread mode - **Event loop never terminates** Fixes valkey-io#2893, fixes valkey-io#2843 --------- Signed-off-by: yzc-yzc <96833212+yzc-yzc@users.noreply.github.com>
hpatro
pushed a commit
to hpatro/valkey
that referenced
this pull request
Mar 5, 2026
…o#3079) In single-thread mode with --duration, the benchmark could hang indefinitely after the duration elapsed. ## Root Cause Consider the following scenario: **Step 1** (T = 0.99s, duration = 1s): - `readHandler` receives response, calls `clientDone()` - `isBenchmarkFinished()` returns `false` (0.99s < 1s) - `clientDone()` calls `resetClient()` **Step 2** (T = 1.01s): - `writeHandler` is called - `isBenchmarkFinished()` returns `true` (1.01s >= 1s) - `writeHandler` returns early, **no request sent, no read event registered** **Result**: - `readHandler` never triggers → `clientDone()` never called → no `aeStop()` - `showThroughput()` checks `num_threads && isBenchmarkFinished()`, skipping single-thread mode - **Event loop never terminates** Fixes valkey-io#2893, fixes valkey-io#2843 --------- Signed-off-by: yzc-yzc <96833212+yzc-yzc@users.noreply.github.com> Signed-off-by: Harkrishn Patro <bunty.hari@gmail.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.
In single-thread mode with --duration, the benchmark could hang indefinitely after the duration elapsed.
Root Cause
Consider the following scenario:
Step 1 (T = 0.99s, duration = 1s):
readHandlerreceives response, callsclientDone()isBenchmarkFinished()returnsfalse(0.99s < 1s)clientDone()callsresetClient()Step 2 (T = 1.01s):
writeHandleris calledisBenchmarkFinished()returnstrue(1.01s >= 1s)writeHandlerreturns early, no request sent, no read event registeredResult:
readHandlernever triggers →clientDone()never called → noaeStop()showThroughput()checksnum_threads && isBenchmarkFinished(), skipping single-thread modeFixes #2893, fixes #2843