Skip to content

Fix a few file read cancellation bugs - #12643

Merged
jzhou77 merged 1 commit into
apple:mainfrom
jzhou77:mailmap
Jan 17, 2026
Merged

jzhou77 merged 1 commit into
apple:mainfrom
jzhou77:mailmap

Conversation

@jzhou77

@jzhou77 jzhou77 commented Jan 16, 2026 •

Copy link
Copy Markdown
Collaborator

File read can't be cancelled, so we have to hold on the buffer and issue reads.

This was found in #12642 test, seed:

-f ./tests/slow/BulkDumpingS3WithChaos.toml -s 1554084314 -b off

20260116-223043-jzhou-860a6897a9eb32c2 compressed=True data_size=34489903 duration=4665976 ended=100000 fail=1 fail_fast=10 max_runs=100000 pass=99999 priority=100 remaining=0 runtime=0:53:38 sanity=False started=100000 stopped=20260116-232421 submitted=20260116-223043 timeout=5400 username=jzhou

-f ./tests/slow/ParallelRestoreOldBackupCorrectnessAtomicOp.toml -s 223090903 -b on, unrelated error Assertion batchData.isValid() failed @ /root/src/foundationdb/fdbserver/RestoreApplier.actor.cpp 740:.

Code-Reviewer Section

The general pull request guidelines can be found here.

Please check each of the following things and check all boxes before accepting a PR.

  • The PR has a description, explaining both the problem and the solution.
  • The description mentions which forms of testing were done and the testing seems reasonable.
  • Every function/class/actor that was touched is reasonably well documented.

For Release-Branches

If this PR is made against a release-branch, please also check the following:

  • This change/bugfix is a cherry-pick from the next younger branch (younger release-branch or main if this is the youngest branch)
  • There is a good reason why this PR needs to go into a release branch and this reason is documented (either in the description above or in a linked GitHub issue)

File read can't be cancelled, so we have to hold on the buffer and issue reads.

This was found in apple#12642 test, seed:

-f ./tests/slow/BulkDumpingS3WithChaos.toml -s 1554084314 -b off
@jzhou77
jzhou77 requested a review from saintstack January 16, 2026 22:31
@foundationdb-ci

Copy link
Copy Markdown
Contributor

Result of foundationdb-pr-macos on macOS Ventura 13.x

  • Commit ID: 7cad0fe
  • Duration 0:07:36
  • Result: ❌ FAILED
  • Error: Error while executing command: ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i ${HOME}/.ssh_key ec2-user@${MAC_EC2_HOST} rm -rf foundationdb. Reason: exit status 255
  • Build Log terminal output (available for 30 days)
  • Build Workspace zip file of the working directory (available for 30 days)

@foundationdb-ci

Copy link
Copy Markdown
Contributor

Result of foundationdb-pr-clang-ide on Linux RHEL 9

  • Commit ID: 7cad0fe
  • Duration 0:24:45
  • Result: ✅ SUCCEEDED
  • Error: N/A
  • Build Log terminal output (available for 30 days)
  • Build Workspace zip file of the working directory (available for 30 days)

@foundationdb-ci

Copy link
Copy Markdown
Contributor

Result of foundationdb-pr-macos-m1 on macOS Ventura 13.x

  • Commit ID: 7cad0fe
  • Duration 0:34:41
  • Result: ✅ SUCCEEDED
  • Error: N/A
  • Build Log terminal output (available for 30 days)
  • Build Workspace zip file of the working directory (available for 30 days)

@foundationdb-ci

Copy link
Copy Markdown
Contributor

Result of foundationdb-pr-clang-arm on Linux CentOS 7

  • Commit ID: 7cad0fe
  • Duration 0:43:15
  • Result: ✅ SUCCEEDED
  • Error: N/A
  • Build Log terminal output (available for 30 days)
  • Build Workspace zip file of the working directory (available for 30 days)

@foundationdb-ci

Copy link
Copy Markdown
Contributor

Result of foundationdb-pr-clang on Linux RHEL 9

  • Commit ID: 7cad0fe
  • Duration 0:57:00
  • Result: ✅ SUCCEEDED
  • Error: N/A
  • Build Log terminal output (available for 30 days)
  • Build Workspace zip file of the working directory (available for 30 days)

@foundationdb-ci

Copy link
Copy Markdown
Contributor

Result of foundationdb-pr on Linux RHEL 9

  • Commit ID: 7cad0fe
  • Duration 0:59:46
  • Result: ✅ SUCCEEDED
  • Error: N/A
  • Build Log terminal output (available for 30 days)
  • Build Workspace zip file of the working directory (available for 30 days)

@foundationdb-ci

Copy link
Copy Markdown
Contributor

Result of foundationdb-pr-cluster-tests on Linux RHEL 9

  • Commit ID: 7cad0fe
  • Duration 2:09:17
  • Result: ✅ SUCCEEDED
  • Error: N/A
  • Build Log terminal output (available for 30 days)
  • Build Workspace zip file of the working directory (available for 30 days)
  • Cluster Test Logs zip file of the test logs (available for 30 days)

@jzhou77
jzhou77 merged commit 5789c55 into apple:main Jan 17, 2026
spraza added a commit to spraza/foundationdb that referenced this pull request Aug 17, 2026
spraza added a commit to spraza/foundationdb that referenced this pull request Aug 18, 2026
spraza added a commit that referenced this pull request Aug 18, 2026
, #12755) (#13871)

* Fix circular recursion in Snapshot.Option (#12318)

Authored-by: Baptiste Merliot <42059119+BMerliot@users.noreply.github.com>

(cherry picked from commit fba84d9 on main)

* Fix a few file read cancellation bugs (#12643)

(cherry picked from commit 5789c55 on main)

* Fix a DD shutdown crash (#12750)

To reproduce clang build at 7.3.69
seed: -f ./tests/restarting/from_7.3.0_until_7.4.0/SnapTestAttrition-1.toml -s 1392115560 -b on

Setup

- dataDistribution is running its main loop. The actors vector (non-state) holds all the sub-actors including DataDistributionTracker::run.
- trackerCancelled (state bool) is false.
- The tracker has finished trackInitialShards and is sitting inside the loop choose, waiting on multiple futures including loggingTrigger.
- loggingTrigger is state Future<Void>. It was initialized as Void() — an already-completed future. After the first firing, it gets reset to delay(...). So on the very first iteration
   of the loop, it fires immediately.

The trigger — an error in another actor

1. Some other actor in actors throws (e.g. movekeys_conflict from a DDTeamCollection actor). waitForAll(actors) propagates this error out of wait(waitForAll(actors)).
2. Execution enters the catch block at DataDistribution.actor.cpp:1114.
3. Line 1115: trackerCancelled = true.
4. Team collection References are cleared (lines 1129–1131). This destroys DDTeamCollection objects synchronously.
5. The error is not actor_cancelled, so we reach line 1142: wait(shards.clearAsync()). The actor suspends here. shards is a state KeyRangeMap<ShardTrackedData> — clearing a large map
is broken into async chunks to avoid starving the event loop.

The pending network response fires during the yield

6. The FDB simulator event loop picks up the next task: a WaitMetrics reply from a storage server arrives for one of the trackShardMetrics actors.
7. SAV<StorageMetrics>::finishSendAndDelPromiseRef() fires its callbacks synchronously in a chain:

    - TrackShardMetricsActor receives the WaitMetrics reply and updates its AsyncVar<Optional<ShardMetrics>> via set().
    - AsyncVar::set destroys the old onChange Promise<Void>, sends to the onChange listeners
    - The QuorumCallback inside changeSizes (or GetFirstSizeActor) fires, completing the quorum. changeSizes completes.
    - trackInitialShards resumes after wait(changeSizes(...)). It calls self->readyToStart.send(Void()), then hits wait(initialSize). If initialSize is already satisfied (all shards
  have reported), trackInitialShards returns.
    - DataDistributionTrackerImpl::run resumes at a_body1cont2 — i.e., after wait(trackInitialShards(...)).
8. Without any trackerCancelled check, run proceeds straight into the loop choose for the first time — a_body1cont2loopHead1 in the generated code.

The crash

9. The loop choose evaluates which futures are ready. loggingTrigger was initialized as Void() and has never been reset yet (this is the first entry into the loop). It is already
  complete.
10. The when(wait(loggingTrigger)) branch fires immediately and executes:
  TraceEvent("DDTrackerStats", self->distributorId)
      .detail("Shards", self->shards->size())   // <-- CRASH
11. self->shards is a raw KeyRangeMap<ShardTrackedData>* pointing at the state shards variable back in dataDistribution. That shards is in the middle of clearAsync() — its internal
  structure is partially destroyed/invalid.
12. Accessing shards->size() on a partially-cleared KeyRangeMap causes a segfault. Signal 11 (SIGSEGV).

(cherry picked from commit 3f15166 on main)

* Track min popped version separately for system localities in TLog (#12755)

(cherry picked from commit df5a98d on main)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants