HLE: fail DirectStorage startup when no worker can start #3207

Open
github-bot wants to merge 2 commits from github-bot/gh-3207 into main AGit
Owner

@⁠yumaste on GitHub · 2026-11-26 12:46 UTC · original
yumaste:fix/dstorage-worker-startup → main · +53 −39 · 1 files · 2 commits · open

Problem

If every DirectStorage worker thread fails to start, the scheduler is still published. Queue creation then succeeds, but there is no worker to run submitted requests. Reads remain pending and a caller waiting for completion or queue capacity can hang.

Change

Publish the scheduler only after at least one worker starts. If none start, queue creation and staging configuration report E_OUTOFMEMORY. A partial worker pool still services queues. The process still attempts initialization once. The title stops at startup when staging setup fails, as noted at the call site. It now sees the error there instead of hanging while waiting for I/O.

Validation

  • Simulated zero successful spawns and one successful spawn after an initial failure. Removing the zero-worker guard makes the regression fail.
  • cargo test --locked -p victory-hle -- --test-threads=1: 153 unit tests and 2 integration tests passed on Windows.
  • cargo clippy --locked -p victory-hle --all-targets --all-features -- -D warnings and cargo xtask policy passed.

Coordination claim. Synthetic test data only. AI-assisted (Codex).

**@⁠yumaste** on GitHub · 2026-11-26 12:46 UTC · [original](https://github.com/Marvisak/VIctory/pull/3207) `yumaste:fix/dstorage-worker-startup` → `main` · +53 −39 · 1 files · 2 commits · open ## Problem If every DirectStorage worker thread fails to start, the scheduler is still published. Queue creation then succeeds, but there is no worker to run submitted requests. Reads remain pending and a caller waiting for completion or queue capacity can hang. ## Change Publish the scheduler only after at least one worker starts. If none start, queue creation and staging configuration report `E_OUTOFMEMORY`. A partial worker pool still services queues. The process still attempts initialization once. The title stops at startup when staging setup fails, as noted at the call site. It now sees the error there instead of hanging while waiting for I/O. ## Validation - Simulated zero successful spawns and one successful spawn after an initial failure. Removing the zero-worker guard makes the regression fail. - `cargo test --locked -p victory-hle -- --test-threads=1`: 153 unit tests and 2 integration tests passed on Windows. - `cargo clippy --locked -p victory-hle --all-targets --all-features -- -D warnings` and `cargo xtask policy` passed. [Coordination claim](https://git.gtahub.st/github/Marvisak--VIctory/issues/1633). Synthetic test data only. AI-assisted (Codex).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 12:50:08 +00:00
Author
Owner

@⁠cloph-dsp on GitHub · 2026-11-26 13:03 UTC · original

Independent local verification of head 7088627 on Windows 11, Rust 1.100.0/MSVC:

  • cargo test --locked -p victory-hle --lib -- modules::dstorage::tests::a_scheduler_requires_at_least_one_worker --exact — 1 passed, 0 failed.
  • git diff --check origin/main HEAD — clean.

Used a worktree-local CARGO_TARGET_DIR. The scheduler test uses synthetic spawn closures; no D3D12 device or game assets were used. AI-assisted (Hy4 flash). GPU/driver: N/A (CPU-only).

**@⁠cloph-dsp** on GitHub · 2026-11-26 13:03 UTC · [original](https://github.com/Marvisak/VIctory/pull/3207#issuecomment-7192817811) Independent local verification of head `7088627` on Windows 11, Rust 1.100.0/MSVC: - `cargo test --locked -p victory-hle --lib -- modules::dstorage::tests::a_scheduler_requires_at_least_one_worker --exact` — 1 passed, 0 failed. - `git diff --check origin/main HEAD` — clean. Used a worktree-local `CARGO_TARGET_DIR`. The scheduler test uses synthetic spawn closures; no D3D12 device or game assets were used. AI-assisted (Hy4 flash). GPU/driver: N/A (CPU-only).
Author
Owner

@⁠AurumCarlos on GitHub · 2026-11-26 13:05 UTC · original · reviewed

Looks good to me. The doc comment on scheduler() already promised "None if not even one worker could start", and on main the code never did that: the scheduler was published before STARTED ran, whatever the spawn count. This makes the code match the comment. I checked it against main:

  • Callers: create_queue already maps None to E_OUTOFMEMORY, so with no workers a title now fails at queue creation instead of hanging on its first read. close_lane, queue and submit all need a queue that already exists, so they can't hit None in practice.
  • Spawning inside get_or_init: the workers start while the OnceLock is still initialising. That's safe because work → execute never calls scheduler(), so no worker can block on the cell it's being started from. On main this was guaranteed by the separate Once; now it relies on that call graph, so a short comment on start ("workers must not call scheduler()") would keep it from breaking quietly later.
  • Arc instead of &'static: needed now that the workers start before the scheduler is in the static. The failure path drops it cleanly, and a partial pool keeps its own clones. 👍
  • set_staging_buffer_size: returning E_OUTOFMEMORY there means Grand Theft Auto VI stops at startup (per the comment above it) instead of hanging later. A clear failure is better here. It might be worth one line in the PR description that this is the visible effect for that title.

The test exercises start with injected spawns, which covers the decision itself. The E_OUTOFMEMORY paths stay untested because scheduler() is a process-wide OnceLock, which is fair.

**@⁠AurumCarlos** on GitHub · 2026-11-26 13:05 UTC · [original](https://github.com/Marvisak/VIctory/pull/3207#pullrequestreview-6074631174) · **reviewed** Looks good to me. The doc comment on `scheduler()` already promised "`None` if not even one worker could start", and on `main` the code never did that: the scheduler was published before `STARTED` ran, whatever the spawn count. This makes the code match the comment. I checked it against `main`: - **Callers**: `create_queue` already maps `None` to `E_OUTOFMEMORY`, so with no workers a title now fails at queue creation instead of hanging on its first read. `close_lane`, `queue` and `submit` all need a queue that already exists, so they can't hit `None` in practice. - **Spawning inside `get_or_init`**: the workers start while the `OnceLock` is still initialising. That's safe because `work` → `execute` never calls `scheduler()`, so no worker can block on the cell it's being started from. On `main` this was guaranteed by the separate `Once`; now it relies on that call graph, so a short comment on `start` ("workers must not call `scheduler()`") would keep it from breaking quietly later. - **`Arc` instead of `&'static`**: needed now that the workers start before the scheduler is in the static. The failure path drops it cleanly, and a partial pool keeps its own clones. 👍 - **`set_staging_buffer_size`**: returning `E_OUTOFMEMORY` there means Grand Theft Auto VI stops at startup (per the comment above it) instead of hanging later. A clear failure is better here. It might be worth one line in the PR description that this is the visible effect for that title. The test exercises `start` with injected spawns, which covers the decision itself. The `E_OUTOFMEMORY` paths stay untested because `scheduler()` is a process-wide `OnceLock`, which is fair.
Author
Owner

@⁠yumaste on GitHub · 2026-11-26 13:12 UTC · original

Thanks. 09dadaf documents why workers receive the scheduler directly and must not call scheduler() while the OnceLock is initializing. I also added the startup behavior to the PR description. The synthetic scheduler test still passes.

**@⁠yumaste** on GitHub · 2026-11-26 13:12 UTC · [original](https://github.com/Marvisak/VIctory/pull/3207#issuecomment-7193031358) Thanks. `09dadaf` documents why workers receive the scheduler directly and must not call `scheduler()` while the `OnceLock` is initializing. I also added the startup behavior to the PR description. The synthetic scheduler test still passes.
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/3207/head:github-bot/gh-3207'
git switch 'github-bot/gh-3207'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3207'
git switch 'github-bot/gh-3207'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3207'
git switch 'github-bot/gh-3207'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3207'
git switch 'main'
git merge --squash 'github-bot/gh-3207'
git switch 'main'
git merge --ff-only 'github-bot/gh-3207'
git switch 'main'
git merge 'github-bot/gh-3207'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!3207
No description provided.