Skip to content

Deflake diskless timeout rdb pipe test by tolerating either timeout-disconnect branch - #3772

Merged
sarthakaggarwal97 merged 5 commits into
valkey-io:unstablefrom
Taeknology:fix/diskless-timeout-3686
Jun 30, 2026
Merged

sarthakaggarwal97 merged 5 commits into
valkey-io:unstablefrom
Taeknology:fix/diskless-timeout-3686

Conversation

@Taeknology

Copy link
Copy Markdown
Contributor

Fixes #3686.

Symptom

tests/integration/replication.tcl "diskless timeout replicas drop during rdb pipe" fails on test-macos-latest:

log message of '"*Disconnecting timedout replica (full sync)*"' not found in
./tests/tmp/server.13581.2852/stdout after line: 128 till line: 151

The master did fire a timeout disconnect, but on the streaming-sync branch instead of the full-sync one:

01:58:34.346 * Streamed RDB transfer with replica 127.0.0.1:22549 succeeded (socket).
01:58:34.346 * Synchronization with replica 127.0.0.1:22549 succeeded
01:58:37.373 # Disconnecting timedout replica (streaming sync): 127.0.0.1:22548

Root cause: same-tick cron ordering

serverCron does two things in the same tick that compete here:

  1. checkChildrenDone (src/server.c:1453) reaps the RDB child and calls backgroundSaveDoneHandler, which clears server.rdb_child_type = RDB_CHILD_TYPE_NONE at src/rdb.c:3698.
  2. The disconnect loop at src/replication.c:5348 runs.

The (full sync) branch (src/replication.c:5369-5377) is gated on rdb_child_type == RDB_CHILD_TYPE_SOCKET. Once step 1 clears it, the branch is unreachable for the rest of that tick. The SIGSTOP'd replica meanwhile was already promoted via replicaPutOnline() (src/replication.c:2006-2031), so the disconnect lands in the (streaming sync) branch at src/replication.c:5357-5364 instead.

On Linux CI, SIGSTOP back-pressure keeps the RDB child blocked on write() to the parent pipe long enough that step 1 does not run in the same tick as step 2. On macOS-latest CI the child drains faster (larger loopback SO_SNDBUF, different scheduler quanta), so the two events collapse into one tick and the test's strict (full sync) wait never matches.

Fix

Accept either timeout-disconnect message, then assert exactly one such disconnect occurred so the test still rejects a regression that emits zero or multiple timeouts:

if {[catch {
    wait_for_log_messages -2 {"*Disconnecting timedout replica (full sync)*"} $loglines 100 100
}]} {
    wait_for_log_messages -2 {"*Disconnecting timedout replica (streaming sync)*"} $loglines 100 100
}
assert_equal 1 [count_log_message -2 "Disconnecting timedout replica"]

Both branches represent a legitimate timeout-driven disconnect; the test's intent ("the slow replica is dropped because of repl-timeout") is preserved. The count_log_message assertion guards against silently widening to "any timeout anywhere".

Prior art in this test

The same catch { wait_for_log_messages ... } + fallback pattern is already the established convention in this very test block to absorb RDB-pipe race variance — see the post-disconnect assertions for all_drop == "all" and all_drop == "slow" at tests/integration/replication.tcl:1011-1036. The comment ("RDB finished before replicas were killed; accept either 1 or 2 replicas still up at pipe-read time.") describes the same kind of timing variance this PR addresses for the timeout subcase on the disconnect-emission side.

Alternatives considered

  • Synchronize pause_process on partial-write evidence: rejected. Once rdb_child_type is cleared in the same tick, no test-side synchronization can force the (full sync) path to fire.
  • Diagnostic logging at src/replication.c:5360,5373 (state + rdb_child_type at disconnect): deferred to a separate follow-up PR. Useful for future triage but independent review surface, and this PR is intentionally test-only.

Verification

  • grep -n "Disconnecting timedout replica" src/replication.c confirms both emitters intact (:5360 streaming, :5373 full).
  • grep -rn "Disconnecting timedout replica (full sync)" tests/ confirms no other test relies on the strict string.
  • Full local run of integration/replication on macOS Apple Silicon: 111 passed, 0 failed.
  • 10-loop run of the five diskless * replicas drop during rdb pipe subcases (including timeout): 50/50 pass. The race is only reproducible on CI VM conditions, so local runs validate non-regression rather than fix efficacy.
  • Post-disconnect assertions at replication.tcl:988-1080 (rdb_bgsave_in_progress, replicas_alive cleanup, dbsize parity, debug digest) are all branch-agnostic.

@coderabbitai

coderabbitai Bot commented May 19, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: a3f06019-4eae-4b73-a729-ac5d2df937f3

📥 Commits

Reviewing files that changed from the base of the PR and between 95849c9 and c959e6b.

📒 Files selected for processing (1)
  • tests/integration/replication.tcl
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/integration/replication.tcl

📝 Walkthrough

Walkthrough

The test for diskless RDB pipe timeout handling now accepts either full-sync or streaming-sync disconnect logs, checks that the timedout replica log appears once, and restores repl-timeout after the check.

Changes

Timeout disconnection test robustness

Layer / File(s) Summary
Timeout disconnection log handling in diskless RDB pipe test
tests/integration/replication.tcl
The all_drop == "timeout" subcase waits for either timeout disconnect log variant, asserts the generic timedout replica log appears exactly once, and restores repl-timeout to 60 afterward.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Suggested reviewers

  • ranshid
  • enjoy-binbin
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the test flake fix and the main behavioral change.
Description check ✅ Passed The description directly explains the CI failure and the test-only fix.
Linked Issues check ✅ Passed The change matches #3686 by accepting either disconnect log and still asserting one timeout disconnect.
Out of Scope Changes check ✅ Passed The PR stays focused on the reported integration test and adds no unrelated changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/integration/replication.tcl`:
- Line 998: Update the failing test assertion so it provides a descriptive error
message: change the assert_equal that compares 1 with the result of
count_log_message(... "Disconnecting timedout replica") to include a clear
message explaining the expectation (e.g., that exactly one "Disconnecting
timedout replica" log entry should be present). Locate the assertion using the
assert_equal call and the count_log_message invocation and add the descriptive
string as the assertion's message argument.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 183ac616-8bc0-4e1b-a69e-330ce23c468a

📥 Commits

Reviewing files that changed from the base of the PR and between 8274099 and 93eac07.

📒 Files selected for processing (1)
  • tests/integration/replication.tcl

Comment thread tests/integration/replication.tcl Resolved
…isconnect branch

The "diskless timeout replicas drop during rdb pipe" subcase in
tests/integration/replication.tcl waits for a "(full sync)" timeout
disconnect log. On test-macos-latest the disconnect can surface on the
"(streaming sync)" branch instead, because the RDB child exits and
clears server.rdb_child_type (src/rdb.c:3698) in the same serverCron
tick as the disconnect loop (src/replication.c:5348), closing the
(full sync) window before it can fire. The timed-out replica is by then
already promoted via replicaPutOnline(), so it falls into the
(streaming sync) branch (src/replication.c:5357-5364). Linux CI does
not hit this because SIGSTOP back-pressure keeps the RDB child blocked
on the pipe write long enough that backgroundSaveDoneHandler does not
run in the same tick.

Accept either timeout-disconnect message and assert exactly one such
disconnect occurred, so the test still rejects a regression that emits
zero or multiple timeouts. This follows the existing catch+fallback
convention already used in the same test for "all" and "slow"
subcases (replication.tcl:1011-1036).

Also addresses CodeRabbit feedback by adding a descriptive failure
message to the `assert_equal 1 [count_log_message ...]` guard so a
regression that emits zero or multiple timeout-disconnect log lines
surfaces with context instead of a bare `Expected '1' to be equal
to '0'`.

Fixes valkey-io#3686.

Signed-off-by: Taeknology <[email protected]>
@Taeknology
Taeknology force-pushed the fix/diskless-timeout-3686 branch from 93eac07 to 95849c9 Compare May 19, 2026 09:36

@rainsupreme rainsupreme left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty solid 👍
I might like to see a workflow that ran this 100x to show it isn't flaky any more, but your in-depth analysis convinces me that this is understood and worth fixing

@codecov

codecov Bot commented Jun 23, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 76.75%. Comparing base (689906a) to head (5a0ef5b).

Additional details and impacted files
@@             Coverage Diff              @@
##           unstable    #3772      +/-   ##
============================================
+ Coverage     76.73%   76.75%   +0.02%     
============================================
  Files           162      162              
  Lines         81029    81029              
============================================
+ Hits          62175    62196      +21     
+ Misses        18854    18833      -21     

see 24 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@sarthakaggarwal97 sarthakaggarwal97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The deep dive looks good and the change makes sense, I just have a minor comment.

Comment thread tests/integration/replication.tcl Resolved

@sarthakaggarwal97 sarthakaggarwal97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, it would be good to run it 100 times as well. As I mentioned here too - #3764 (review)

Use a single multi-pattern wait_for_log_messages for the "(full sync)" and "(streaming sync)" cases, as suggested in review. Keep the assert_equal count guard.

Signed-off-by: Taeknology <[email protected]>
@Taeknology

Copy link
Copy Markdown
Contributor Author

Thanks @sarthakaggarwal97 and @rainsupreme for all the guidance — I'm not very familiar with the contribution process yet, so it was really helpful.

Ran the test 100 times locally — all 100 passed, no failures.

./runtest --single integration/replication --loops 10 --clients 1   # run 10 times = 100 iterations

diskless timeout replicas drop during rdb pipe: 100/100 passed
0 failures / 0 exceptions, each run 4.5–5.7s

@enjoy-binbin enjoy-binbin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems OK to me, thanks.

@sarthakaggarwal97
sarthakaggarwal97 merged commit 5b690ce into valkey-io:unstable Jun 30, 2026
76 of 77 checks passed
@Taeknology

Copy link
Copy Markdown
Contributor Author

Thanks @sarthakaggarwal97 for merging, and @rainsupreme @enjoy-binbin for the reviews.
This was my first real contribution here and the feedback made the process much easier to follow. 🙏

vansvan17 pushed a commit to vansvan17/valkey that referenced this pull request Jul 9, 2026
…isconnect branch (valkey-io#3772)

Fixes valkey-io#3686.

### Symptom

`tests/integration/replication.tcl` "diskless timeout replicas drop
during rdb pipe" fails on `test-macos-latest`:

```
log message of '"*Disconnecting timedout replica (full sync)*"' not found in
./tests/tmp/server.13581.2852/stdout after line: 128 till line: 151
```

The master *did* fire a timeout disconnect, but on the streaming-sync
branch instead of the full-sync one:

```
01:58:34.346 * Streamed RDB transfer with replica 127.0.0.1:22549 succeeded (socket).
01:58:34.346 * Synchronization with replica 127.0.0.1:22549 succeeded
01:58:37.373 # Disconnecting timedout replica (streaming sync): 127.0.0.1:22548
```

### Root cause: same-tick cron ordering

`serverCron` does two things in the same tick that compete here:

1. `checkChildrenDone` (`src/server.c:1453`) reaps the RDB child and
calls `backgroundSaveDoneHandler`, which clears `server.rdb_child_type =
RDB_CHILD_TYPE_NONE` at `src/rdb.c:3698`.
2. The disconnect loop at `src/replication.c:5348` runs.

The `(full sync)` branch (`src/replication.c:5369-5377`) is gated on
`rdb_child_type == RDB_CHILD_TYPE_SOCKET`. Once step 1 clears it, the
branch is unreachable for the rest of that tick. The SIGSTOP'd replica
meanwhile was already promoted via `replicaPutOnline()`
(`src/replication.c:2006-2031`), so the disconnect lands in the
`(streaming sync)` branch at `src/replication.c:5357-5364` instead.

On Linux CI, SIGSTOP back-pressure keeps the RDB child blocked on
`write()` to the parent pipe long enough that step 1 does not run in the
same tick as step 2. On macOS-latest CI the child drains faster (larger
loopback `SO_SNDBUF`, different scheduler quanta), so the two events
collapse into one tick and the test's strict `(full sync)` wait never
matches.

### Fix

Accept either timeout-disconnect message, then assert exactly one such
disconnect occurred so the test still rejects a regression that emits
zero or multiple timeouts:

```tcl
if {[catch {
    wait_for_log_messages -2 {"*Disconnecting timedout replica (full sync)*"} $loglines 100 100
}]} {
    wait_for_log_messages -2 {"*Disconnecting timedout replica (streaming sync)*"} $loglines 100 100
}
assert_equal 1 [count_log_message -2 "Disconnecting timedout replica"]
```

Both branches represent a legitimate timeout-driven disconnect; the
test's intent ("the slow replica is dropped because of `repl-timeout`")
is preserved. The `count_log_message` assertion guards against silently
widening to "any timeout anywhere".

### Prior art in this test

The same `catch { wait_for_log_messages ... }` + fallback pattern is
already the established convention in this very test block to absorb
RDB-pipe race variance — see the post-disconnect assertions for
`all_drop == "all"` and `all_drop == "slow"` at
`tests/integration/replication.tcl:1011-1036`. The comment ("RDB
finished before replicas were killed; accept either 1 or 2 replicas
still up at pipe-read time.") describes the same kind of timing variance
this PR addresses for the timeout subcase on the disconnect-emission
side.

### Alternatives considered

- **Synchronize `pause_process` on partial-write evidence**: rejected.
Once `rdb_child_type` is cleared in the same tick, no test-side
synchronization can force the `(full sync)` path to fire.
- **Diagnostic logging at `src/replication.c:5360,5373`** (state +
`rdb_child_type` at disconnect): deferred to a separate follow-up PR.
Useful for future triage but independent review surface, and this PR is
intentionally test-only.

### Verification

- `grep -n "Disconnecting timedout replica" src/replication.c` confirms
both emitters intact (`:5360` streaming, `:5373` full).
- `grep -rn "Disconnecting timedout replica (full sync)" tests/`
confirms no other test relies on the strict string.
- Full local run of `integration/replication` on macOS Apple Silicon:
111 passed, 0 failed.
- 10-loop run of the five `diskless * replicas drop during rdb pipe`
subcases (including timeout): 50/50 pass. The race is only reproducible
on CI VM conditions, so local runs validate non-regression rather than
fix efficacy.
- Post-disconnect assertions at `replication.tcl:988-1080`
(rdb_bgsave_in_progress, replicas_alive cleanup, dbsize parity, debug
digest) are all branch-agnostic.

---------

Signed-off-by: Taeknology <[email protected]>
Co-authored-by: Sarthak Aggarwal <[email protected]>
Signed-off-by: Vanshika <[email protected]>
alon-arenberg pushed a commit to alon-arenberg/valkey that referenced this pull request Jul 15, 2026
…isconnect branch (valkey-io#3772)

Fixes valkey-io#3686.

### Symptom

`tests/integration/replication.tcl` "diskless timeout replicas drop
during rdb pipe" fails on `test-macos-latest`:

```
log message of '"*Disconnecting timedout replica (full sync)*"' not found in
./tests/tmp/server.13581.2852/stdout after line: 128 till line: 151
```

The master *did* fire a timeout disconnect, but on the streaming-sync
branch instead of the full-sync one:

```
01:58:34.346 * Streamed RDB transfer with replica 127.0.0.1:22549 succeeded (socket).
01:58:34.346 * Synchronization with replica 127.0.0.1:22549 succeeded
01:58:37.373 # Disconnecting timedout replica (streaming sync): 127.0.0.1:22548
```

### Root cause: same-tick cron ordering

`serverCron` does two things in the same tick that compete here:

1. `checkChildrenDone` (`src/server.c:1453`) reaps the RDB child and
calls `backgroundSaveDoneHandler`, which clears `server.rdb_child_type =
RDB_CHILD_TYPE_NONE` at `src/rdb.c:3698`.
2. The disconnect loop at `src/replication.c:5348` runs.

The `(full sync)` branch (`src/replication.c:5369-5377`) is gated on
`rdb_child_type == RDB_CHILD_TYPE_SOCKET`. Once step 1 clears it, the
branch is unreachable for the rest of that tick. The SIGSTOP'd replica
meanwhile was already promoted via `replicaPutOnline()`
(`src/replication.c:2006-2031`), so the disconnect lands in the
`(streaming sync)` branch at `src/replication.c:5357-5364` instead.

On Linux CI, SIGSTOP back-pressure keeps the RDB child blocked on
`write()` to the parent pipe long enough that step 1 does not run in the
same tick as step 2. On macOS-latest CI the child drains faster (larger
loopback `SO_SNDBUF`, different scheduler quanta), so the two events
collapse into one tick and the test's strict `(full sync)` wait never
matches.

### Fix

Accept either timeout-disconnect message, then assert exactly one such
disconnect occurred so the test still rejects a regression that emits
zero or multiple timeouts:

```tcl
if {[catch {
    wait_for_log_messages -2 {"*Disconnecting timedout replica (full sync)*"} $loglines 100 100
}]} {
    wait_for_log_messages -2 {"*Disconnecting timedout replica (streaming sync)*"} $loglines 100 100
}
assert_equal 1 [count_log_message -2 "Disconnecting timedout replica"]
```

Both branches represent a legitimate timeout-driven disconnect; the
test's intent ("the slow replica is dropped because of `repl-timeout`")
is preserved. The `count_log_message` assertion guards against silently
widening to "any timeout anywhere".

### Prior art in this test

The same `catch { wait_for_log_messages ... }` + fallback pattern is
already the established convention in this very test block to absorb
RDB-pipe race variance — see the post-disconnect assertions for
`all_drop == "all"` and `all_drop == "slow"` at
`tests/integration/replication.tcl:1011-1036`. The comment ("RDB
finished before replicas were killed; accept either 1 or 2 replicas
still up at pipe-read time.") describes the same kind of timing variance
this PR addresses for the timeout subcase on the disconnect-emission
side.

### Alternatives considered

- **Synchronize `pause_process` on partial-write evidence**: rejected.
Once `rdb_child_type` is cleared in the same tick, no test-side
synchronization can force the `(full sync)` path to fire.
- **Diagnostic logging at `src/replication.c:5360,5373`** (state +
`rdb_child_type` at disconnect): deferred to a separate follow-up PR.
Useful for future triage but independent review surface, and this PR is
intentionally test-only.

### Verification

- `grep -n "Disconnecting timedout replica" src/replication.c` confirms
both emitters intact (`:5360` streaming, `:5373` full).
- `grep -rn "Disconnecting timedout replica (full sync)" tests/`
confirms no other test relies on the strict string.
- Full local run of `integration/replication` on macOS Apple Silicon:
111 passed, 0 failed.
- 10-loop run of the five `diskless * replicas drop during rdb pipe`
subcases (including timeout): 50/50 pass. The race is only reproducible
on CI VM conditions, so local runs validate non-regression rather than
fix efficacy.
- Post-disconnect assertions at `replication.tcl:988-1080`
(rdb_bgsave_in_progress, replicas_alive cleanup, dbsize parity, debug
digest) are all branch-agnostic.

---------

Signed-off-by: Taeknology <[email protected]>
Co-authored-by: Sarthak Aggarwal <[email protected]>
Signed-off-by: Alon Arenberg <[email protected]>
@Taeknology
Taeknology deleted the fix/diskless-timeout-3686 branch July 15, 2026 10:23
alon-arenberg pushed a commit to alon-arenberg/valkey that referenced this pull request Jul 30, 2026
…isconnect branch (valkey-io#3772)

Fixes valkey-io#3686.

### Symptom

`tests/integration/replication.tcl` "diskless timeout replicas drop
during rdb pipe" fails on `test-macos-latest`:

```
log message of '"*Disconnecting timedout replica (full sync)*"' not found in
./tests/tmp/server.13581.2852/stdout after line: 128 till line: 151
```

The master *did* fire a timeout disconnect, but on the streaming-sync
branch instead of the full-sync one:

```
01:58:34.346 * Streamed RDB transfer with replica 127.0.0.1:22549 succeeded (socket).
01:58:34.346 * Synchronization with replica 127.0.0.1:22549 succeeded
01:58:37.373 # Disconnecting timedout replica (streaming sync): 127.0.0.1:22548
```

### Root cause: same-tick cron ordering

`serverCron` does two things in the same tick that compete here:

1. `checkChildrenDone` (`src/server.c:1453`) reaps the RDB child and
calls `backgroundSaveDoneHandler`, which clears `server.rdb_child_type =
RDB_CHILD_TYPE_NONE` at `src/rdb.c:3698`.
2. The disconnect loop at `src/replication.c:5348` runs.

The `(full sync)` branch (`src/replication.c:5369-5377`) is gated on
`rdb_child_type == RDB_CHILD_TYPE_SOCKET`. Once step 1 clears it, the
branch is unreachable for the rest of that tick. The SIGSTOP'd replica
meanwhile was already promoted via `replicaPutOnline()`
(`src/replication.c:2006-2031`), so the disconnect lands in the
`(streaming sync)` branch at `src/replication.c:5357-5364` instead.

On Linux CI, SIGSTOP back-pressure keeps the RDB child blocked on
`write()` to the parent pipe long enough that step 1 does not run in the
same tick as step 2. On macOS-latest CI the child drains faster (larger
loopback `SO_SNDBUF`, different scheduler quanta), so the two events
collapse into one tick and the test's strict `(full sync)` wait never
matches.

### Fix

Accept either timeout-disconnect message, then assert exactly one such
disconnect occurred so the test still rejects a regression that emits
zero or multiple timeouts:

```tcl
if {[catch {
    wait_for_log_messages -2 {"*Disconnecting timedout replica (full sync)*"} $loglines 100 100
}]} {
    wait_for_log_messages -2 {"*Disconnecting timedout replica (streaming sync)*"} $loglines 100 100
}
assert_equal 1 [count_log_message -2 "Disconnecting timedout replica"]
```

Both branches represent a legitimate timeout-driven disconnect; the
test's intent ("the slow replica is dropped because of `repl-timeout`")
is preserved. The `count_log_message` assertion guards against silently
widening to "any timeout anywhere".

### Prior art in this test

The same `catch { wait_for_log_messages ... }` + fallback pattern is
already the established convention in this very test block to absorb
RDB-pipe race variance — see the post-disconnect assertions for
`all_drop == "all"` and `all_drop == "slow"` at
`tests/integration/replication.tcl:1011-1036`. The comment ("RDB
finished before replicas were killed; accept either 1 or 2 replicas
still up at pipe-read time.") describes the same kind of timing variance
this PR addresses for the timeout subcase on the disconnect-emission
side.

### Alternatives considered

- **Synchronize `pause_process` on partial-write evidence**: rejected.
Once `rdb_child_type` is cleared in the same tick, no test-side
synchronization can force the `(full sync)` path to fire.
- **Diagnostic logging at `src/replication.c:5360,5373`** (state +
`rdb_child_type` at disconnect): deferred to a separate follow-up PR.
Useful for future triage but independent review surface, and this PR is
intentionally test-only.

### Verification

- `grep -n "Disconnecting timedout replica" src/replication.c` confirms
both emitters intact (`:5360` streaming, `:5373` full).
- `grep -rn "Disconnecting timedout replica (full sync)" tests/`
confirms no other test relies on the strict string.
- Full local run of `integration/replication` on macOS Apple Silicon:
111 passed, 0 failed.
- 10-loop run of the five `diskless * replicas drop during rdb pipe`
subcases (including timeout): 50/50 pass. The race is only reproducible
on CI VM conditions, so local runs validate non-regression rather than
fix efficacy.
- Post-disconnect assertions at `replication.tcl:988-1080`
(rdb_bgsave_in_progress, replicas_alive cleanup, dbsize parity, debug
digest) are all branch-agnostic.

---------

Signed-off-by: Taeknology <[email protected]>
Co-authored-by: Sarthak Aggarwal <[email protected]>
Signed-off-by: Alon Arenberg <[email protected]>
@rainsupreme rainsupreme moved this to To be backported in Valkey 9.1 Nov 11, 2026
@rainsupreme rainsupreme moved this to To be backported in Valkey 9.0 Nov 11, 2026
@rainsupreme rainsupreme moved this to To be backported in Valkey 8.1 Nov 11, 2026
@rainsupreme rainsupreme moved this to To be backported in Valkey 8.0 Nov 11, 2026
@rainsupreme rainsupreme moved this to To be backported in Valkey 7.2 Nov 11, 2026
valkeyrie-ops Bot pushed a commit that referenced this pull request Nov 12, 2026
…isconnect branch (#3772)

Fixes #3686.

### Symptom

`tests/integration/replication.tcl` "diskless timeout replicas drop
during rdb pipe" fails on `test-macos-latest`:

```
log message of '"*Disconnecting timedout replica (full sync)*"' not found in
./tests/tmp/server.13581.2852/stdout after line: 128 till line: 151
```

The master *did* fire a timeout disconnect, but on the streaming-sync
branch instead of the full-sync one:

```
01:58:34.346 * Streamed RDB transfer with replica 127.0.0.1:22549 succeeded (socket).
01:58:34.346 * Synchronization with replica 127.0.0.1:22549 succeeded
01:58:37.373 # Disconnecting timedout replica (streaming sync): 127.0.0.1:22548
```

### Root cause: same-tick cron ordering

`serverCron` does two things in the same tick that compete here:

1. `checkChildrenDone` (`src/server.c:1453`) reaps the RDB child and
calls `backgroundSaveDoneHandler`, which clears `server.rdb_child_type =
RDB_CHILD_TYPE_NONE` at `src/rdb.c:3698`.
2. The disconnect loop at `src/replication.c:5348` runs.

The `(full sync)` branch (`src/replication.c:5369-5377`) is gated on
`rdb_child_type == RDB_CHILD_TYPE_SOCKET`. Once step 1 clears it, the
branch is unreachable for the rest of that tick. The SIGSTOP'd replica
meanwhile was already promoted via `replicaPutOnline()`
(`src/replication.c:2006-2031`), so the disconnect lands in the
`(streaming sync)` branch at `src/replication.c:5357-5364` instead.

On Linux CI, SIGSTOP back-pressure keeps the RDB child blocked on
`write()` to the parent pipe long enough that step 1 does not run in the
same tick as step 2. On macOS-latest CI the child drains faster (larger
loopback `SO_SNDBUF`, different scheduler quanta), so the two events
collapse into one tick and the test's strict `(full sync)` wait never
matches.

### Fix

Accept either timeout-disconnect message, then assert exactly one such
disconnect occurred so the test still rejects a regression that emits
zero or multiple timeouts:

```tcl
if {[catch {
    wait_for_log_messages -2 {"*Disconnecting timedout replica (full sync)*"} $loglines 100 100
}]} {
    wait_for_log_messages -2 {"*Disconnecting timedout replica (streaming sync)*"} $loglines 100 100
}
assert_equal 1 [count_log_message -2 "Disconnecting timedout replica"]
```

Both branches represent a legitimate timeout-driven disconnect; the
test's intent ("the slow replica is dropped because of `repl-timeout`")
is preserved. The `count_log_message` assertion guards against silently
widening to "any timeout anywhere".

### Prior art in this test

The same `catch { wait_for_log_messages ... }` + fallback pattern is
already the established convention in this very test block to absorb
RDB-pipe race variance — see the post-disconnect assertions for
`all_drop == "all"` and `all_drop == "slow"` at
`tests/integration/replication.tcl:1011-1036`. The comment ("RDB
finished before replicas were killed; accept either 1 or 2 replicas
still up at pipe-read time.") describes the same kind of timing variance
this PR addresses for the timeout subcase on the disconnect-emission
side.

### Alternatives considered

- **Synchronize `pause_process` on partial-write evidence**: rejected.
Once `rdb_child_type` is cleared in the same tick, no test-side
synchronization can force the `(full sync)` path to fire.
- **Diagnostic logging at `src/replication.c:5360,5373`** (state +
`rdb_child_type` at disconnect): deferred to a separate follow-up PR.
Useful for future triage but independent review surface, and this PR is
intentionally test-only.

### Verification

- `grep -n "Disconnecting timedout replica" src/replication.c` confirms
both emitters intact (`:5360` streaming, `:5373` full).
- `grep -rn "Disconnecting timedout replica (full sync)" tests/`
confirms no other test relies on the strict string.
- Full local run of `integration/replication` on macOS Apple Silicon:
111 passed, 0 failed.
- 10-loop run of the five `diskless * replicas drop during rdb pipe`
subcases (including timeout): 50/50 pass. The race is only reproducible
on CI VM conditions, so local runs validate non-regression rather than
fix efficacy.
- Post-disconnect assertions at `replication.tcl:988-1080`
(rdb_bgsave_in_progress, replicas_alive cleanup, dbsize parity, debug
digest) are all branch-agnostic.

---------

Signed-off-by: Taeknology <[email protected]>
Co-authored-by: Sarthak Aggarwal <[email protected]>
Backport-Source-PR: 3772
valkeyrie-ops Bot pushed a commit that referenced this pull request Nov 12, 2026
…isconnect branch (#3772)

Fixes #3686.

### Symptom

`tests/integration/replication.tcl` "diskless timeout replicas drop
during rdb pipe" fails on `test-macos-latest`:

```
log message of '"*Disconnecting timedout replica (full sync)*"' not found in
./tests/tmp/server.13581.2852/stdout after line: 128 till line: 151
```

The master *did* fire a timeout disconnect, but on the streaming-sync
branch instead of the full-sync one:

```
01:58:34.346 * Streamed RDB transfer with replica 127.0.0.1:22549 succeeded (socket).
01:58:34.346 * Synchronization with replica 127.0.0.1:22549 succeeded
01:58:37.373 # Disconnecting timedout replica (streaming sync): 127.0.0.1:22548
```

### Root cause: same-tick cron ordering

`serverCron` does two things in the same tick that compete here:

1. `checkChildrenDone` (`src/server.c:1453`) reaps the RDB child and
calls `backgroundSaveDoneHandler`, which clears `server.rdb_child_type =
RDB_CHILD_TYPE_NONE` at `src/rdb.c:3698`.
2. The disconnect loop at `src/replication.c:5348` runs.

The `(full sync)` branch (`src/replication.c:5369-5377`) is gated on
`rdb_child_type == RDB_CHILD_TYPE_SOCKET`. Once step 1 clears it, the
branch is unreachable for the rest of that tick. The SIGSTOP'd replica
meanwhile was already promoted via `replicaPutOnline()`
(`src/replication.c:2006-2031`), so the disconnect lands in the
`(streaming sync)` branch at `src/replication.c:5357-5364` instead.

On Linux CI, SIGSTOP back-pressure keeps the RDB child blocked on
`write()` to the parent pipe long enough that step 1 does not run in the
same tick as step 2. On macOS-latest CI the child drains faster (larger
loopback `SO_SNDBUF`, different scheduler quanta), so the two events
collapse into one tick and the test's strict `(full sync)` wait never
matches.

### Fix

Accept either timeout-disconnect message, then assert exactly one such
disconnect occurred so the test still rejects a regression that emits
zero or multiple timeouts:

```tcl
if {[catch {
    wait_for_log_messages -2 {"*Disconnecting timedout replica (full sync)*"} $loglines 100 100
}]} {
    wait_for_log_messages -2 {"*Disconnecting timedout replica (streaming sync)*"} $loglines 100 100
}
assert_equal 1 [count_log_message -2 "Disconnecting timedout replica"]
```

Both branches represent a legitimate timeout-driven disconnect; the
test's intent ("the slow replica is dropped because of `repl-timeout`")
is preserved. The `count_log_message` assertion guards against silently
widening to "any timeout anywhere".

### Prior art in this test

The same `catch { wait_for_log_messages ... }` + fallback pattern is
already the established convention in this very test block to absorb
RDB-pipe race variance — see the post-disconnect assertions for
`all_drop == "all"` and `all_drop == "slow"` at
`tests/integration/replication.tcl:1011-1036`. The comment ("RDB
finished before replicas were killed; accept either 1 or 2 replicas
still up at pipe-read time.") describes the same kind of timing variance
this PR addresses for the timeout subcase on the disconnect-emission
side.

### Alternatives considered

- **Synchronize `pause_process` on partial-write evidence**: rejected.
Once `rdb_child_type` is cleared in the same tick, no test-side
synchronization can force the `(full sync)` path to fire.
- **Diagnostic logging at `src/replication.c:5360,5373`** (state +
`rdb_child_type` at disconnect): deferred to a separate follow-up PR.
Useful for future triage but independent review surface, and this PR is
intentionally test-only.

### Verification

- `grep -n "Disconnecting timedout replica" src/replication.c` confirms
both emitters intact (`:5360` streaming, `:5373` full).
- `grep -rn "Disconnecting timedout replica (full sync)" tests/`
confirms no other test relies on the strict string.
- Full local run of `integration/replication` on macOS Apple Silicon:
111 passed, 0 failed.
- 10-loop run of the five `diskless * replicas drop during rdb pipe`
subcases (including timeout): 50/50 pass. The race is only reproducible
on CI VM conditions, so local runs validate non-regression rather than
fix efficacy.
- Post-disconnect assertions at `replication.tcl:988-1080`
(rdb_bgsave_in_progress, replicas_alive cleanup, dbsize parity, debug
digest) are all branch-agnostic.

---------

Signed-off-by: Taeknology <[email protected]>
Co-authored-by: Sarthak Aggarwal <[email protected]>
Backport-Source-PR: 3772
valkeyrie-ops Bot pushed a commit that referenced this pull request Nov 12, 2026
…isconnect branch (#3772)

Fixes #3686.

### Symptom

`tests/integration/replication.tcl` "diskless timeout replicas drop
during rdb pipe" fails on `test-macos-latest`:

```
log message of '"*Disconnecting timedout replica (full sync)*"' not found in
./tests/tmp/server.13581.2852/stdout after line: 128 till line: 151
```

The master *did* fire a timeout disconnect, but on the streaming-sync
branch instead of the full-sync one:

```
01:58:34.346 * Streamed RDB transfer with replica 127.0.0.1:22549 succeeded (socket).
01:58:34.346 * Synchronization with replica 127.0.0.1:22549 succeeded
01:58:37.373 # Disconnecting timedout replica (streaming sync): 127.0.0.1:22548
```

### Root cause: same-tick cron ordering

`serverCron` does two things in the same tick that compete here:

1. `checkChildrenDone` (`src/server.c:1453`) reaps the RDB child and
calls `backgroundSaveDoneHandler`, which clears `server.rdb_child_type =
RDB_CHILD_TYPE_NONE` at `src/rdb.c:3698`.
2. The disconnect loop at `src/replication.c:5348` runs.

The `(full sync)` branch (`src/replication.c:5369-5377`) is gated on
`rdb_child_type == RDB_CHILD_TYPE_SOCKET`. Once step 1 clears it, the
branch is unreachable for the rest of that tick. The SIGSTOP'd replica
meanwhile was already promoted via `replicaPutOnline()`
(`src/replication.c:2006-2031`), so the disconnect lands in the
`(streaming sync)` branch at `src/replication.c:5357-5364` instead.

On Linux CI, SIGSTOP back-pressure keeps the RDB child blocked on
`write()` to the parent pipe long enough that step 1 does not run in the
same tick as step 2. On macOS-latest CI the child drains faster (larger
loopback `SO_SNDBUF`, different scheduler quanta), so the two events
collapse into one tick and the test's strict `(full sync)` wait never
matches.

### Fix

Accept either timeout-disconnect message, then assert exactly one such
disconnect occurred so the test still rejects a regression that emits
zero or multiple timeouts:

```tcl
if {[catch {
    wait_for_log_messages -2 {"*Disconnecting timedout replica (full sync)*"} $loglines 100 100
}]} {
    wait_for_log_messages -2 {"*Disconnecting timedout replica (streaming sync)*"} $loglines 100 100
}
assert_equal 1 [count_log_message -2 "Disconnecting timedout replica"]
```

Both branches represent a legitimate timeout-driven disconnect; the
test's intent ("the slow replica is dropped because of `repl-timeout`")
is preserved. The `count_log_message` assertion guards against silently
widening to "any timeout anywhere".

### Prior art in this test

The same `catch { wait_for_log_messages ... }` + fallback pattern is
already the established convention in this very test block to absorb
RDB-pipe race variance — see the post-disconnect assertions for
`all_drop == "all"` and `all_drop == "slow"` at
`tests/integration/replication.tcl:1011-1036`. The comment ("RDB
finished before replicas were killed; accept either 1 or 2 replicas
still up at pipe-read time.") describes the same kind of timing variance
this PR addresses for the timeout subcase on the disconnect-emission
side.

### Alternatives considered

- **Synchronize `pause_process` on partial-write evidence**: rejected.
Once `rdb_child_type` is cleared in the same tick, no test-side
synchronization can force the `(full sync)` path to fire.
- **Diagnostic logging at `src/replication.c:5360,5373`** (state +
`rdb_child_type` at disconnect): deferred to a separate follow-up PR.
Useful for future triage but independent review surface, and this PR is
intentionally test-only.

### Verification

- `grep -n "Disconnecting timedout replica" src/replication.c` confirms
both emitters intact (`:5360` streaming, `:5373` full).
- `grep -rn "Disconnecting timedout replica (full sync)" tests/`
confirms no other test relies on the strict string.
- Full local run of `integration/replication` on macOS Apple Silicon:
111 passed, 0 failed.
- 10-loop run of the five `diskless * replicas drop during rdb pipe`
subcases (including timeout): 50/50 pass. The race is only reproducible
on CI VM conditions, so local runs validate non-regression rather than
fix efficacy.
- Post-disconnect assertions at `replication.tcl:988-1080`
(rdb_bgsave_in_progress, replicas_alive cleanup, dbsize parity, debug
digest) are all branch-agnostic.

---------

Signed-off-by: Taeknology <[email protected]>
Co-authored-by: Sarthak Aggarwal <[email protected]>
Backport-Source-PR: 3772
valkeyrie-ops Bot pushed a commit that referenced this pull request Nov 12, 2026
…isconnect branch (#3772)

Fixes #3686.

### Symptom

`tests/integration/replication.tcl` "diskless timeout replicas drop
during rdb pipe" fails on `test-macos-latest`:

```
log message of '"*Disconnecting timedout replica (full sync)*"' not found in
./tests/tmp/server.13581.2852/stdout after line: 128 till line: 151
```

The master *did* fire a timeout disconnect, but on the streaming-sync
branch instead of the full-sync one:

```
01:58:34.346 * Streamed RDB transfer with replica 127.0.0.1:22549 succeeded (socket).
01:58:34.346 * Synchronization with replica 127.0.0.1:22549 succeeded
01:58:37.373 # Disconnecting timedout replica (streaming sync): 127.0.0.1:22548
```

### Root cause: same-tick cron ordering

`serverCron` does two things in the same tick that compete here:

1. `checkChildrenDone` (`src/server.c:1453`) reaps the RDB child and
calls `backgroundSaveDoneHandler`, which clears `server.rdb_child_type =
RDB_CHILD_TYPE_NONE` at `src/rdb.c:3698`.
2. The disconnect loop at `src/replication.c:5348` runs.

The `(full sync)` branch (`src/replication.c:5369-5377`) is gated on
`rdb_child_type == RDB_CHILD_TYPE_SOCKET`. Once step 1 clears it, the
branch is unreachable for the rest of that tick. The SIGSTOP'd replica
meanwhile was already promoted via `replicaPutOnline()`
(`src/replication.c:2006-2031`), so the disconnect lands in the
`(streaming sync)` branch at `src/replication.c:5357-5364` instead.

On Linux CI, SIGSTOP back-pressure keeps the RDB child blocked on
`write()` to the parent pipe long enough that step 1 does not run in the
same tick as step 2. On macOS-latest CI the child drains faster (larger
loopback `SO_SNDBUF`, different scheduler quanta), so the two events
collapse into one tick and the test's strict `(full sync)` wait never
matches.

### Fix

Accept either timeout-disconnect message, then assert exactly one such
disconnect occurred so the test still rejects a regression that emits
zero or multiple timeouts:

```tcl
if {[catch {
    wait_for_log_messages -2 {"*Disconnecting timedout replica (full sync)*"} $loglines 100 100
}]} {
    wait_for_log_messages -2 {"*Disconnecting timedout replica (streaming sync)*"} $loglines 100 100
}
assert_equal 1 [count_log_message -2 "Disconnecting timedout replica"]
```

Both branches represent a legitimate timeout-driven disconnect; the
test's intent ("the slow replica is dropped because of `repl-timeout`")
is preserved. The `count_log_message` assertion guards against silently
widening to "any timeout anywhere".

### Prior art in this test

The same `catch { wait_for_log_messages ... }` + fallback pattern is
already the established convention in this very test block to absorb
RDB-pipe race variance — see the post-disconnect assertions for
`all_drop == "all"` and `all_drop == "slow"` at
`tests/integration/replication.tcl:1011-1036`. The comment ("RDB
finished before replicas were killed; accept either 1 or 2 replicas
still up at pipe-read time.") describes the same kind of timing variance
this PR addresses for the timeout subcase on the disconnect-emission
side.

### Alternatives considered

- **Synchronize `pause_process` on partial-write evidence**: rejected.
Once `rdb_child_type` is cleared in the same tick, no test-side
synchronization can force the `(full sync)` path to fire.
- **Diagnostic logging at `src/replication.c:5360,5373`** (state +
`rdb_child_type` at disconnect): deferred to a separate follow-up PR.
Useful for future triage but independent review surface, and this PR is
intentionally test-only.

### Verification

- `grep -n "Disconnecting timedout replica" src/replication.c` confirms
both emitters intact (`:5360` streaming, `:5373` full).
- `grep -rn "Disconnecting timedout replica (full sync)" tests/`
confirms no other test relies on the strict string.
- Full local run of `integration/replication` on macOS Apple Silicon:
111 passed, 0 failed.
- 10-loop run of the five `diskless * replicas drop during rdb pipe`
subcases (including timeout): 50/50 pass. The race is only reproducible
on CI VM conditions, so local runs validate non-regression rather than
fix efficacy.
- Post-disconnect assertions at `replication.tcl:988-1080`
(rdb_bgsave_in_progress, replicas_alive cleanup, dbsize parity, debug
digest) are all branch-agnostic.

---------

Signed-off-by: Taeknology <[email protected]>
Co-authored-by: Sarthak Aggarwal <[email protected]>
Backport-Source-PR: 3772
valkeyrie-ops Bot pushed a commit that referenced this pull request Nov 12, 2026
…isconnect branch (#3772)

Fixes #3686.

### Symptom

`tests/integration/replication.tcl` "diskless timeout replicas drop
during rdb pipe" fails on `test-macos-latest`:

```
log message of '"*Disconnecting timedout replica (full sync)*"' not found in
./tests/tmp/server.13581.2852/stdout after line: 128 till line: 151
```

The master *did* fire a timeout disconnect, but on the streaming-sync
branch instead of the full-sync one:

```
01:58:34.346 * Streamed RDB transfer with replica 127.0.0.1:22549 succeeded (socket).
01:58:34.346 * Synchronization with replica 127.0.0.1:22549 succeeded
01:58:37.373 # Disconnecting timedout replica (streaming sync): 127.0.0.1:22548
```

### Root cause: same-tick cron ordering

`serverCron` does two things in the same tick that compete here:

1. `checkChildrenDone` (`src/server.c:1453`) reaps the RDB child and
calls `backgroundSaveDoneHandler`, which clears `server.rdb_child_type =
RDB_CHILD_TYPE_NONE` at `src/rdb.c:3698`.
2. The disconnect loop at `src/replication.c:5348` runs.

The `(full sync)` branch (`src/replication.c:5369-5377`) is gated on
`rdb_child_type == RDB_CHILD_TYPE_SOCKET`. Once step 1 clears it, the
branch is unreachable for the rest of that tick. The SIGSTOP'd replica
meanwhile was already promoted via `replicaPutOnline()`
(`src/replication.c:2006-2031`), so the disconnect lands in the
`(streaming sync)` branch at `src/replication.c:5357-5364` instead.

On Linux CI, SIGSTOP back-pressure keeps the RDB child blocked on
`write()` to the parent pipe long enough that step 1 does not run in the
same tick as step 2. On macOS-latest CI the child drains faster (larger
loopback `SO_SNDBUF`, different scheduler quanta), so the two events
collapse into one tick and the test's strict `(full sync)` wait never
matches.

### Fix

Accept either timeout-disconnect message, then assert exactly one such
disconnect occurred so the test still rejects a regression that emits
zero or multiple timeouts:

```tcl
if {[catch {
    wait_for_log_messages -2 {"*Disconnecting timedout replica (full sync)*"} $loglines 100 100
}]} {
    wait_for_log_messages -2 {"*Disconnecting timedout replica (streaming sync)*"} $loglines 100 100
}
assert_equal 1 [count_log_message -2 "Disconnecting timedout replica"]
```

Both branches represent a legitimate timeout-driven disconnect; the
test's intent ("the slow replica is dropped because of `repl-timeout`")
is preserved. The `count_log_message` assertion guards against silently
widening to "any timeout anywhere".

### Prior art in this test

The same `catch { wait_for_log_messages ... }` + fallback pattern is
already the established convention in this very test block to absorb
RDB-pipe race variance — see the post-disconnect assertions for
`all_drop == "all"` and `all_drop == "slow"` at
`tests/integration/replication.tcl:1011-1036`. The comment ("RDB
finished before replicas were killed; accept either 1 or 2 replicas
still up at pipe-read time.") describes the same kind of timing variance
this PR addresses for the timeout subcase on the disconnect-emission
side.

### Alternatives considered

- **Synchronize `pause_process` on partial-write evidence**: rejected.
Once `rdb_child_type` is cleared in the same tick, no test-side
synchronization can force the `(full sync)` path to fire.
- **Diagnostic logging at `src/replication.c:5360,5373`** (state +
`rdb_child_type` at disconnect): deferred to a separate follow-up PR.
Useful for future triage but independent review surface, and this PR is
intentionally test-only.

### Verification

- `grep -n "Disconnecting timedout replica" src/replication.c` confirms
both emitters intact (`:5360` streaming, `:5373` full).
- `grep -rn "Disconnecting timedout replica (full sync)" tests/`
confirms no other test relies on the strict string.
- Full local run of `integration/replication` on macOS Apple Silicon:
111 passed, 0 failed.
- 10-loop run of the five `diskless * replicas drop during rdb pipe`
subcases (including timeout): 50/50 pass. The race is only reproducible
on CI VM conditions, so local runs validate non-regression rather than
fix efficacy.
- Post-disconnect assertions at `replication.tcl:988-1080`
(rdb_bgsave_in_progress, replicas_alive cleanup, dbsize parity, debug
digest) are all branch-agnostic.

---------

Signed-off-by: Taeknology <[email protected]>
Co-authored-by: Sarthak Aggarwal <[email protected]>
Backport-Source-PR: 3772
sarthakaggarwal97 added a commit that referenced this pull request Nov 18, 2026
…isconnect branch (#3772)

Fixes #3686.

### Symptom

`tests/integration/replication.tcl` "diskless timeout replicas drop
during rdb pipe" fails on `test-macos-latest`:

```
log message of '"*Disconnecting timedout replica (full sync)*"' not found in
./tests/tmp/server.13581.2852/stdout after line: 128 till line: 151
```

The master *did* fire a timeout disconnect, but on the streaming-sync
branch instead of the full-sync one:

```
01:58:34.346 * Streamed RDB transfer with replica 127.0.0.1:22549 succeeded (socket).
01:58:34.346 * Synchronization with replica 127.0.0.1:22549 succeeded
01:58:37.373 # Disconnecting timedout replica (streaming sync): 127.0.0.1:22548
```

### Root cause: same-tick cron ordering

`serverCron` does two things in the same tick that compete here:

1. `checkChildrenDone` (`src/server.c:1453`) reaps the RDB child and
calls `backgroundSaveDoneHandler`, which clears `server.rdb_child_type =
RDB_CHILD_TYPE_NONE` at `src/rdb.c:3698`.
2. The disconnect loop at `src/replication.c:5348` runs.

The `(full sync)` branch (`src/replication.c:5369-5377`) is gated on
`rdb_child_type == RDB_CHILD_TYPE_SOCKET`. Once step 1 clears it, the
branch is unreachable for the rest of that tick. The SIGSTOP'd replica
meanwhile was already promoted via `replicaPutOnline()`
(`src/replication.c:2006-2031`), so the disconnect lands in the
`(streaming sync)` branch at `src/replication.c:5357-5364` instead.

On Linux CI, SIGSTOP back-pressure keeps the RDB child blocked on
`write()` to the parent pipe long enough that step 1 does not run in the
same tick as step 2. On macOS-latest CI the child drains faster (larger
loopback `SO_SNDBUF`, different scheduler quanta), so the two events
collapse into one tick and the test's strict `(full sync)` wait never
matches.

### Fix

Accept either timeout-disconnect message, then assert exactly one such
disconnect occurred so the test still rejects a regression that emits
zero or multiple timeouts:

```tcl
if {[catch {
    wait_for_log_messages -2 {"*Disconnecting timedout replica (full sync)*"} $loglines 100 100
}]} {
    wait_for_log_messages -2 {"*Disconnecting timedout replica (streaming sync)*"} $loglines 100 100
}
assert_equal 1 [count_log_message -2 "Disconnecting timedout replica"]
```

Both branches represent a legitimate timeout-driven disconnect; the
test's intent ("the slow replica is dropped because of `repl-timeout`")
is preserved. The `count_log_message` assertion guards against silently
widening to "any timeout anywhere".

### Prior art in this test

The same `catch { wait_for_log_messages ... }` + fallback pattern is
already the established convention in this very test block to absorb
RDB-pipe race variance — see the post-disconnect assertions for
`all_drop == "all"` and `all_drop == "slow"` at
`tests/integration/replication.tcl:1011-1036`. The comment ("RDB
finished before replicas were killed; accept either 1 or 2 replicas
still up at pipe-read time.") describes the same kind of timing variance
this PR addresses for the timeout subcase on the disconnect-emission
side.

### Alternatives considered

- **Synchronize `pause_process` on partial-write evidence**: rejected.
Once `rdb_child_type` is cleared in the same tick, no test-side
synchronization can force the `(full sync)` path to fire.
- **Diagnostic logging at `src/replication.c:5360,5373`** (state +
`rdb_child_type` at disconnect): deferred to a separate follow-up PR.
Useful for future triage but independent review surface, and this PR is
intentionally test-only.

### Verification

- `grep -n "Disconnecting timedout replica" src/replication.c` confirms
both emitters intact (`:5360` streaming, `:5373` full).
- `grep -rn "Disconnecting timedout replica (full sync)" tests/`
confirms no other test relies on the strict string.
- Full local run of `integration/replication` on macOS Apple Silicon:
111 passed, 0 failed.
- 10-loop run of the five `diskless * replicas drop during rdb pipe`
subcases (including timeout): 50/50 pass. The race is only reproducible
on CI VM conditions, so local runs validate non-regression rather than
fix efficacy.
- Post-disconnect assertions at `replication.tcl:988-1080`
(rdb_bgsave_in_progress, replicas_alive cleanup, dbsize parity, debug
digest) are all branch-agnostic.

---------

Signed-off-by: Taeknology <[email protected]>
Co-authored-by: Sarthak Aggarwal <[email protected]>
Backport-Source-PR: 3772
sarthakaggarwal97 added a commit that referenced this pull request Nov 18, 2026
…isconnect branch (#3772)

Fixes #3686.

### Symptom

`tests/integration/replication.tcl` "diskless timeout replicas drop
during rdb pipe" fails on `test-macos-latest`:

```
log message of '"*Disconnecting timedout replica (full sync)*"' not found in
./tests/tmp/server.13581.2852/stdout after line: 128 till line: 151
```

The master *did* fire a timeout disconnect, but on the streaming-sync
branch instead of the full-sync one:

```
01:58:34.346 * Streamed RDB transfer with replica 127.0.0.1:22549 succeeded (socket).
01:58:34.346 * Synchronization with replica 127.0.0.1:22549 succeeded
01:58:37.373 # Disconnecting timedout replica (streaming sync): 127.0.0.1:22548
```

### Root cause: same-tick cron ordering

`serverCron` does two things in the same tick that compete here:

1. `checkChildrenDone` (`src/server.c:1453`) reaps the RDB child and
calls `backgroundSaveDoneHandler`, which clears `server.rdb_child_type =
RDB_CHILD_TYPE_NONE` at `src/rdb.c:3698`.
2. The disconnect loop at `src/replication.c:5348` runs.

The `(full sync)` branch (`src/replication.c:5369-5377`) is gated on
`rdb_child_type == RDB_CHILD_TYPE_SOCKET`. Once step 1 clears it, the
branch is unreachable for the rest of that tick. The SIGSTOP'd replica
meanwhile was already promoted via `replicaPutOnline()`
(`src/replication.c:2006-2031`), so the disconnect lands in the
`(streaming sync)` branch at `src/replication.c:5357-5364` instead.

On Linux CI, SIGSTOP back-pressure keeps the RDB child blocked on
`write()` to the parent pipe long enough that step 1 does not run in the
same tick as step 2. On macOS-latest CI the child drains faster (larger
loopback `SO_SNDBUF`, different scheduler quanta), so the two events
collapse into one tick and the test's strict `(full sync)` wait never
matches.

### Fix

Accept either timeout-disconnect message, then assert exactly one such
disconnect occurred so the test still rejects a regression that emits
zero or multiple timeouts:

```tcl
if {[catch {
    wait_for_log_messages -2 {"*Disconnecting timedout replica (full sync)*"} $loglines 100 100
}]} {
    wait_for_log_messages -2 {"*Disconnecting timedout replica (streaming sync)*"} $loglines 100 100
}
assert_equal 1 [count_log_message -2 "Disconnecting timedout replica"]
```

Both branches represent a legitimate timeout-driven disconnect; the
test's intent ("the slow replica is dropped because of `repl-timeout`")
is preserved. The `count_log_message` assertion guards against silently
widening to "any timeout anywhere".

### Prior art in this test

The same `catch { wait_for_log_messages ... }` + fallback pattern is
already the established convention in this very test block to absorb
RDB-pipe race variance — see the post-disconnect assertions for
`all_drop == "all"` and `all_drop == "slow"` at
`tests/integration/replication.tcl:1011-1036`. The comment ("RDB
finished before replicas were killed; accept either 1 or 2 replicas
still up at pipe-read time.") describes the same kind of timing variance
this PR addresses for the timeout subcase on the disconnect-emission
side.

### Alternatives considered

- **Synchronize `pause_process` on partial-write evidence**: rejected.
Once `rdb_child_type` is cleared in the same tick, no test-side
synchronization can force the `(full sync)` path to fire.
- **Diagnostic logging at `src/replication.c:5360,5373`** (state +
`rdb_child_type` at disconnect): deferred to a separate follow-up PR.
Useful for future triage but independent review surface, and this PR is
intentionally test-only.

### Verification

- `grep -n "Disconnecting timedout replica" src/replication.c` confirms
both emitters intact (`:5360` streaming, `:5373` full).
- `grep -rn "Disconnecting timedout replica (full sync)" tests/`
confirms no other test relies on the strict string.
- Full local run of `integration/replication` on macOS Apple Silicon:
111 passed, 0 failed.
- 10-loop run of the five `diskless * replicas drop during rdb pipe`
subcases (including timeout): 50/50 pass. The race is only reproducible
on CI VM conditions, so local runs validate non-regression rather than
fix efficacy.
- Post-disconnect assertions at `replication.tcl:988-1080`
(rdb_bgsave_in_progress, replicas_alive cleanup, dbsize parity, debug
digest) are all branch-agnostic.

---------

Signed-off-by: Taeknology <[email protected]>
Co-authored-by: Sarthak Aggarwal <[email protected]>
Backport-Source-PR: 3772
sarthakaggarwal97 added a commit that referenced this pull request Nov 18, 2026
…isconnect branch (#3772)

Fixes #3686.

### Symptom

`tests/integration/replication.tcl` "diskless timeout replicas drop
during rdb pipe" fails on `test-macos-latest`:

```
log message of '"*Disconnecting timedout replica (full sync)*"' not found in
./tests/tmp/server.13581.2852/stdout after line: 128 till line: 151
```

The master *did* fire a timeout disconnect, but on the streaming-sync
branch instead of the full-sync one:

```
01:58:34.346 * Streamed RDB transfer with replica 127.0.0.1:22549 succeeded (socket).
01:58:34.346 * Synchronization with replica 127.0.0.1:22549 succeeded
01:58:37.373 # Disconnecting timedout replica (streaming sync): 127.0.0.1:22548
```

### Root cause: same-tick cron ordering

`serverCron` does two things in the same tick that compete here:

1. `checkChildrenDone` (`src/server.c:1453`) reaps the RDB child and
calls `backgroundSaveDoneHandler`, which clears `server.rdb_child_type =
RDB_CHILD_TYPE_NONE` at `src/rdb.c:3698`.
2. The disconnect loop at `src/replication.c:5348` runs.

The `(full sync)` branch (`src/replication.c:5369-5377`) is gated on
`rdb_child_type == RDB_CHILD_TYPE_SOCKET`. Once step 1 clears it, the
branch is unreachable for the rest of that tick. The SIGSTOP'd replica
meanwhile was already promoted via `replicaPutOnline()`
(`src/replication.c:2006-2031`), so the disconnect lands in the
`(streaming sync)` branch at `src/replication.c:5357-5364` instead.

On Linux CI, SIGSTOP back-pressure keeps the RDB child blocked on
`write()` to the parent pipe long enough that step 1 does not run in the
same tick as step 2. On macOS-latest CI the child drains faster (larger
loopback `SO_SNDBUF`, different scheduler quanta), so the two events
collapse into one tick and the test's strict `(full sync)` wait never
matches.

### Fix

Accept either timeout-disconnect message, then assert exactly one such
disconnect occurred so the test still rejects a regression that emits
zero or multiple timeouts:

```tcl
if {[catch {
    wait_for_log_messages -2 {"*Disconnecting timedout replica (full sync)*"} $loglines 100 100
}]} {
    wait_for_log_messages -2 {"*Disconnecting timedout replica (streaming sync)*"} $loglines 100 100
}
assert_equal 1 [count_log_message -2 "Disconnecting timedout replica"]
```

Both branches represent a legitimate timeout-driven disconnect; the
test's intent ("the slow replica is dropped because of `repl-timeout`")
is preserved. The `count_log_message` assertion guards against silently
widening to "any timeout anywhere".

### Prior art in this test

The same `catch { wait_for_log_messages ... }` + fallback pattern is
already the established convention in this very test block to absorb
RDB-pipe race variance — see the post-disconnect assertions for
`all_drop == "all"` and `all_drop == "slow"` at
`tests/integration/replication.tcl:1011-1036`. The comment ("RDB
finished before replicas were killed; accept either 1 or 2 replicas
still up at pipe-read time.") describes the same kind of timing variance
this PR addresses for the timeout subcase on the disconnect-emission
side.

### Alternatives considered

- **Synchronize `pause_process` on partial-write evidence**: rejected.
Once `rdb_child_type` is cleared in the same tick, no test-side
synchronization can force the `(full sync)` path to fire.
- **Diagnostic logging at `src/replication.c:5360,5373`** (state +
`rdb_child_type` at disconnect): deferred to a separate follow-up PR.
Useful for future triage but independent review surface, and this PR is
intentionally test-only.

### Verification

- `grep -n "Disconnecting timedout replica" src/replication.c` confirms
both emitters intact (`:5360` streaming, `:5373` full).
- `grep -rn "Disconnecting timedout replica (full sync)" tests/`
confirms no other test relies on the strict string.
- Full local run of `integration/replication` on macOS Apple Silicon:
111 passed, 0 failed.
- 10-loop run of the five `diskless * replicas drop during rdb pipe`
subcases (including timeout): 50/50 pass. The race is only reproducible
on CI VM conditions, so local runs validate non-regression rather than
fix efficacy.
- Post-disconnect assertions at `replication.tcl:988-1080`
(rdb_bgsave_in_progress, replicas_alive cleanup, dbsize parity, debug
digest) are all branch-agnostic.

---------

Signed-off-by: Taeknology <[email protected]>
Co-authored-by: Sarthak Aggarwal <[email protected]>
Backport-Source-PR: 3772
@valkeyrie-ops valkeyrie-ops Bot moved this from To be backported to Done in Valkey 7.2 Nov 18, 2026
sarthakaggarwal97 added a commit that referenced this pull request Nov 18, 2026
…isconnect branch (#3772)

Fixes #3686.

### Symptom

`tests/integration/replication.tcl` "diskless timeout replicas drop
during rdb pipe" fails on `test-macos-latest`:

```
log message of '"*Disconnecting timedout replica (full sync)*"' not found in
./tests/tmp/server.13581.2852/stdout after line: 128 till line: 151
```

The master *did* fire a timeout disconnect, but on the streaming-sync
branch instead of the full-sync one:

```
01:58:34.346 * Streamed RDB transfer with replica 127.0.0.1:22549 succeeded (socket).
01:58:34.346 * Synchronization with replica 127.0.0.1:22549 succeeded
01:58:37.373 # Disconnecting timedout replica (streaming sync): 127.0.0.1:22548
```

### Root cause: same-tick cron ordering

`serverCron` does two things in the same tick that compete here:

1. `checkChildrenDone` (`src/server.c:1453`) reaps the RDB child and
calls `backgroundSaveDoneHandler`, which clears `server.rdb_child_type =
RDB_CHILD_TYPE_NONE` at `src/rdb.c:3698`.
2. The disconnect loop at `src/replication.c:5348` runs.

The `(full sync)` branch (`src/replication.c:5369-5377`) is gated on
`rdb_child_type == RDB_CHILD_TYPE_SOCKET`. Once step 1 clears it, the
branch is unreachable for the rest of that tick. The SIGSTOP'd replica
meanwhile was already promoted via `replicaPutOnline()`
(`src/replication.c:2006-2031`), so the disconnect lands in the
`(streaming sync)` branch at `src/replication.c:5357-5364` instead.

On Linux CI, SIGSTOP back-pressure keeps the RDB child blocked on
`write()` to the parent pipe long enough that step 1 does not run in the
same tick as step 2. On macOS-latest CI the child drains faster (larger
loopback `SO_SNDBUF`, different scheduler quanta), so the two events
collapse into one tick and the test's strict `(full sync)` wait never
matches.

### Fix

Accept either timeout-disconnect message, then assert exactly one such
disconnect occurred so the test still rejects a regression that emits
zero or multiple timeouts:

```tcl
if {[catch {
    wait_for_log_messages -2 {"*Disconnecting timedout replica (full sync)*"} $loglines 100 100
}]} {
    wait_for_log_messages -2 {"*Disconnecting timedout replica (streaming sync)*"} $loglines 100 100
}
assert_equal 1 [count_log_message -2 "Disconnecting timedout replica"]
```

Both branches represent a legitimate timeout-driven disconnect; the
test's intent ("the slow replica is dropped because of `repl-timeout`")
is preserved. The `count_log_message` assertion guards against silently
widening to "any timeout anywhere".

### Prior art in this test

The same `catch { wait_for_log_messages ... }` + fallback pattern is
already the established convention in this very test block to absorb
RDB-pipe race variance — see the post-disconnect assertions for
`all_drop == "all"` and `all_drop == "slow"` at
`tests/integration/replication.tcl:1011-1036`. The comment ("RDB
finished before replicas were killed; accept either 1 or 2 replicas
still up at pipe-read time.") describes the same kind of timing variance
this PR addresses for the timeout subcase on the disconnect-emission
side.

### Alternatives considered

- **Synchronize `pause_process` on partial-write evidence**: rejected.
Once `rdb_child_type` is cleared in the same tick, no test-side
synchronization can force the `(full sync)` path to fire.
- **Diagnostic logging at `src/replication.c:5360,5373`** (state +
`rdb_child_type` at disconnect): deferred to a separate follow-up PR.
Useful for future triage but independent review surface, and this PR is
intentionally test-only.

### Verification

- `grep -n "Disconnecting timedout replica" src/replication.c` confirms
both emitters intact (`:5360` streaming, `:5373` full).
- `grep -rn "Disconnecting timedout replica (full sync)" tests/`
confirms no other test relies on the strict string.
- Full local run of `integration/replication` on macOS Apple Silicon:
111 passed, 0 failed.
- 10-loop run of the five `diskless * replicas drop during rdb pipe`
subcases (including timeout): 50/50 pass. The race is only reproducible
on CI VM conditions, so local runs validate non-regression rather than
fix efficacy.
- Post-disconnect assertions at `replication.tcl:988-1080`
(rdb_bgsave_in_progress, replicas_alive cleanup, dbsize parity, debug
digest) are all branch-agnostic.

---------

Signed-off-by: Taeknology <[email protected]>
Co-authored-by: Sarthak Aggarwal <[email protected]>
Backport-Source-PR: 3772
@valkeyrie-ops valkeyrie-ops Bot moved this from To be backported to Done in Valkey 9.1 Nov 18, 2026
sarthakaggarwal97 added a commit that referenced this pull request Nov 18, 2026
…isconnect branch (#3772)

Fixes #3686.

### Symptom

`tests/integration/replication.tcl` "diskless timeout replicas drop
during rdb pipe" fails on `test-macos-latest`:

```
log message of '"*Disconnecting timedout replica (full sync)*"' not found in
./tests/tmp/server.13581.2852/stdout after line: 128 till line: 151
```

The master *did* fire a timeout disconnect, but on the streaming-sync
branch instead of the full-sync one:

```
01:58:34.346 * Streamed RDB transfer with replica 127.0.0.1:22549 succeeded (socket).
01:58:34.346 * Synchronization with replica 127.0.0.1:22549 succeeded
01:58:37.373 # Disconnecting timedout replica (streaming sync): 127.0.0.1:22548
```

### Root cause: same-tick cron ordering

`serverCron` does two things in the same tick that compete here:

1. `checkChildrenDone` (`src/server.c:1453`) reaps the RDB child and
calls `backgroundSaveDoneHandler`, which clears `server.rdb_child_type =
RDB_CHILD_TYPE_NONE` at `src/rdb.c:3698`.
2. The disconnect loop at `src/replication.c:5348` runs.

The `(full sync)` branch (`src/replication.c:5369-5377`) is gated on
`rdb_child_type == RDB_CHILD_TYPE_SOCKET`. Once step 1 clears it, the
branch is unreachable for the rest of that tick. The SIGSTOP'd replica
meanwhile was already promoted via `replicaPutOnline()`
(`src/replication.c:2006-2031`), so the disconnect lands in the
`(streaming sync)` branch at `src/replication.c:5357-5364` instead.

On Linux CI, SIGSTOP back-pressure keeps the RDB child blocked on
`write()` to the parent pipe long enough that step 1 does not run in the
same tick as step 2. On macOS-latest CI the child drains faster (larger
loopback `SO_SNDBUF`, different scheduler quanta), so the two events
collapse into one tick and the test's strict `(full sync)` wait never
matches.

### Fix

Accept either timeout-disconnect message, then assert exactly one such
disconnect occurred so the test still rejects a regression that emits
zero or multiple timeouts:

```tcl
if {[catch {
    wait_for_log_messages -2 {"*Disconnecting timedout replica (full sync)*"} $loglines 100 100
}]} {
    wait_for_log_messages -2 {"*Disconnecting timedout replica (streaming sync)*"} $loglines 100 100
}
assert_equal 1 [count_log_message -2 "Disconnecting timedout replica"]
```

Both branches represent a legitimate timeout-driven disconnect; the
test's intent ("the slow replica is dropped because of `repl-timeout`")
is preserved. The `count_log_message` assertion guards against silently
widening to "any timeout anywhere".

### Prior art in this test

The same `catch { wait_for_log_messages ... }` + fallback pattern is
already the established convention in this very test block to absorb
RDB-pipe race variance — see the post-disconnect assertions for
`all_drop == "all"` and `all_drop == "slow"` at
`tests/integration/replication.tcl:1011-1036`. The comment ("RDB
finished before replicas were killed; accept either 1 or 2 replicas
still up at pipe-read time.") describes the same kind of timing variance
this PR addresses for the timeout subcase on the disconnect-emission
side.

### Alternatives considered

- **Synchronize `pause_process` on partial-write evidence**: rejected.
Once `rdb_child_type` is cleared in the same tick, no test-side
synchronization can force the `(full sync)` path to fire.
- **Diagnostic logging at `src/replication.c:5360,5373`** (state +
`rdb_child_type` at disconnect): deferred to a separate follow-up PR.
Useful for future triage but independent review surface, and this PR is
intentionally test-only.

### Verification

- `grep -n "Disconnecting timedout replica" src/replication.c` confirms
both emitters intact (`:5360` streaming, `:5373` full).
- `grep -rn "Disconnecting timedout replica (full sync)" tests/`
confirms no other test relies on the strict string.
- Full local run of `integration/replication` on macOS Apple Silicon:
111 passed, 0 failed.
- 10-loop run of the five `diskless * replicas drop during rdb pipe`
subcases (including timeout): 50/50 pass. The race is only reproducible
on CI VM conditions, so local runs validate non-regression rather than
fix efficacy.
- Post-disconnect assertions at `replication.tcl:988-1080`
(rdb_bgsave_in_progress, replicas_alive cleanup, dbsize parity, debug
digest) are all branch-agnostic.

---------

Signed-off-by: Taeknology <[email protected]>
Co-authored-by: Sarthak Aggarwal <[email protected]>
Backport-Source-PR: 3772
@valkeyrie-ops valkeyrie-ops Bot moved this from To be backported to Done in Valkey 8.1 Nov 18, 2026
sarthakaggarwal97 added a commit that referenced this pull request Nov 18, 2026
…isconnect branch (#3772)

Fixes #3686.

### Symptom

`tests/integration/replication.tcl` "diskless timeout replicas drop
during rdb pipe" fails on `test-macos-latest`:

```
log message of '"*Disconnecting timedout replica (full sync)*"' not found in
./tests/tmp/server.13581.2852/stdout after line: 128 till line: 151
```

The master *did* fire a timeout disconnect, but on the streaming-sync
branch instead of the full-sync one:

```
01:58:34.346 * Streamed RDB transfer with replica 127.0.0.1:22549 succeeded (socket).
01:58:34.346 * Synchronization with replica 127.0.0.1:22549 succeeded
01:58:37.373 # Disconnecting timedout replica (streaming sync): 127.0.0.1:22548
```

### Root cause: same-tick cron ordering

`serverCron` does two things in the same tick that compete here:

1. `checkChildrenDone` (`src/server.c:1453`) reaps the RDB child and
calls `backgroundSaveDoneHandler`, which clears `server.rdb_child_type =
RDB_CHILD_TYPE_NONE` at `src/rdb.c:3698`.
2. The disconnect loop at `src/replication.c:5348` runs.

The `(full sync)` branch (`src/replication.c:5369-5377`) is gated on
`rdb_child_type == RDB_CHILD_TYPE_SOCKET`. Once step 1 clears it, the
branch is unreachable for the rest of that tick. The SIGSTOP'd replica
meanwhile was already promoted via `replicaPutOnline()`
(`src/replication.c:2006-2031`), so the disconnect lands in the
`(streaming sync)` branch at `src/replication.c:5357-5364` instead.

On Linux CI, SIGSTOP back-pressure keeps the RDB child blocked on
`write()` to the parent pipe long enough that step 1 does not run in the
same tick as step 2. On macOS-latest CI the child drains faster (larger
loopback `SO_SNDBUF`, different scheduler quanta), so the two events
collapse into one tick and the test's strict `(full sync)` wait never
matches.

### Fix

Accept either timeout-disconnect message, then assert exactly one such
disconnect occurred so the test still rejects a regression that emits
zero or multiple timeouts:

```tcl
if {[catch {
    wait_for_log_messages -2 {"*Disconnecting timedout replica (full sync)*"} $loglines 100 100
}]} {
    wait_for_log_messages -2 {"*Disconnecting timedout replica (streaming sync)*"} $loglines 100 100
}
assert_equal 1 [count_log_message -2 "Disconnecting timedout replica"]
```

Both branches represent a legitimate timeout-driven disconnect; the
test's intent ("the slow replica is dropped because of `repl-timeout`")
is preserved. The `count_log_message` assertion guards against silently
widening to "any timeout anywhere".

### Prior art in this test

The same `catch { wait_for_log_messages ... }` + fallback pattern is
already the established convention in this very test block to absorb
RDB-pipe race variance — see the post-disconnect assertions for
`all_drop == "all"` and `all_drop == "slow"` at
`tests/integration/replication.tcl:1011-1036`. The comment ("RDB
finished before replicas were killed; accept either 1 or 2 replicas
still up at pipe-read time.") describes the same kind of timing variance
this PR addresses for the timeout subcase on the disconnect-emission
side.

### Alternatives considered

- **Synchronize `pause_process` on partial-write evidence**: rejected.
Once `rdb_child_type` is cleared in the same tick, no test-side
synchronization can force the `(full sync)` path to fire.
- **Diagnostic logging at `src/replication.c:5360,5373`** (state +
`rdb_child_type` at disconnect): deferred to a separate follow-up PR.
Useful for future triage but independent review surface, and this PR is
intentionally test-only.

### Verification

- `grep -n "Disconnecting timedout replica" src/replication.c` confirms
both emitters intact (`:5360` streaming, `:5373` full).
- `grep -rn "Disconnecting timedout replica (full sync)" tests/`
confirms no other test relies on the strict string.
- Full local run of `integration/replication` on macOS Apple Silicon:
111 passed, 0 failed.
- 10-loop run of the five `diskless * replicas drop during rdb pipe`
subcases (including timeout): 50/50 pass. The race is only reproducible
on CI VM conditions, so local runs validate non-regression rather than
fix efficacy.
- Post-disconnect assertions at `replication.tcl:988-1080`
(rdb_bgsave_in_progress, replicas_alive cleanup, dbsize parity, debug
digest) are all branch-agnostic.

---------

Signed-off-by: Taeknology <[email protected]>
Co-authored-by: Sarthak Aggarwal <[email protected]>
Backport-Source-PR: 3772
@valkeyrie-ops valkeyrie-ops Bot moved this from To be backported to Done in Valkey 8.0 Nov 18, 2026
sarthakaggarwal97 added a commit that referenced this pull request Nov 18, 2026
…isconnect branch (#3772)

Fixes #3686.

### Symptom

`tests/integration/replication.tcl` "diskless timeout replicas drop
during rdb pipe" fails on `test-macos-latest`:

```
log message of '"*Disconnecting timedout replica (full sync)*"' not found in
./tests/tmp/server.13581.2852/stdout after line: 128 till line: 151
```

The master *did* fire a timeout disconnect, but on the streaming-sync
branch instead of the full-sync one:

```
01:58:34.346 * Streamed RDB transfer with replica 127.0.0.1:22549 succeeded (socket).
01:58:34.346 * Synchronization with replica 127.0.0.1:22549 succeeded
01:58:37.373 # Disconnecting timedout replica (streaming sync): 127.0.0.1:22548
```

### Root cause: same-tick cron ordering

`serverCron` does two things in the same tick that compete here:

1. `checkChildrenDone` (`src/server.c:1453`) reaps the RDB child and
calls `backgroundSaveDoneHandler`, which clears `server.rdb_child_type =
RDB_CHILD_TYPE_NONE` at `src/rdb.c:3698`.
2. The disconnect loop at `src/replication.c:5348` runs.

The `(full sync)` branch (`src/replication.c:5369-5377`) is gated on
`rdb_child_type == RDB_CHILD_TYPE_SOCKET`. Once step 1 clears it, the
branch is unreachable for the rest of that tick. The SIGSTOP'd replica
meanwhile was already promoted via `replicaPutOnline()`
(`src/replication.c:2006-2031`), so the disconnect lands in the
`(streaming sync)` branch at `src/replication.c:5357-5364` instead.

On Linux CI, SIGSTOP back-pressure keeps the RDB child blocked on
`write()` to the parent pipe long enough that step 1 does not run in the
same tick as step 2. On macOS-latest CI the child drains faster (larger
loopback `SO_SNDBUF`, different scheduler quanta), so the two events
collapse into one tick and the test's strict `(full sync)` wait never
matches.

### Fix

Accept either timeout-disconnect message, then assert exactly one such
disconnect occurred so the test still rejects a regression that emits
zero or multiple timeouts:

```tcl
if {[catch {
    wait_for_log_messages -2 {"*Disconnecting timedout replica (full sync)*"} $loglines 100 100
}]} {
    wait_for_log_messages -2 {"*Disconnecting timedout replica (streaming sync)*"} $loglines 100 100
}
assert_equal 1 [count_log_message -2 "Disconnecting timedout replica"]
```

Both branches represent a legitimate timeout-driven disconnect; the
test's intent ("the slow replica is dropped because of `repl-timeout`")
is preserved. The `count_log_message` assertion guards against silently
widening to "any timeout anywhere".

### Prior art in this test

The same `catch { wait_for_log_messages ... }` + fallback pattern is
already the established convention in this very test block to absorb
RDB-pipe race variance — see the post-disconnect assertions for
`all_drop == "all"` and `all_drop == "slow"` at
`tests/integration/replication.tcl:1011-1036`. The comment ("RDB
finished before replicas were killed; accept either 1 or 2 replicas
still up at pipe-read time.") describes the same kind of timing variance
this PR addresses for the timeout subcase on the disconnect-emission
side.

### Alternatives considered

- **Synchronize `pause_process` on partial-write evidence**: rejected.
Once `rdb_child_type` is cleared in the same tick, no test-side
synchronization can force the `(full sync)` path to fire.
- **Diagnostic logging at `src/replication.c:5360,5373`** (state +
`rdb_child_type` at disconnect): deferred to a separate follow-up PR.
Useful for future triage but independent review surface, and this PR is
intentionally test-only.

### Verification

- `grep -n "Disconnecting timedout replica" src/replication.c` confirms
both emitters intact (`:5360` streaming, `:5373` full).
- `grep -rn "Disconnecting timedout replica (full sync)" tests/`
confirms no other test relies on the strict string.
- Full local run of `integration/replication` on macOS Apple Silicon:
111 passed, 0 failed.
- 10-loop run of the five `diskless * replicas drop during rdb pipe`
subcases (including timeout): 50/50 pass. The race is only reproducible
on CI VM conditions, so local runs validate non-regression rather than
fix efficacy.
- Post-disconnect assertions at `replication.tcl:988-1080`
(rdb_bgsave_in_progress, replicas_alive cleanup, dbsize parity, debug
digest) are all branch-agnostic.

---------

Signed-off-by: Taeknology <[email protected]>
Co-authored-by: Sarthak Aggarwal <[email protected]>
Backport-Source-PR: 3772
@valkeyrie-ops valkeyrie-ops Bot moved this from To be backported to Done in Valkey 9.0 Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done
Status: Done
Status: Done
Status: Done
Status: Done

Development

Successfully merging this pull request may close these issues.

[TEST-FAILURE] diskless timeout replicas drop during rdb pipe in tests/integration/replication.tcl

4 participants