Skip to content

tests: never reuse an adapter sandbox's name within a test process - #1463

Merged
Pedro Henrique Penna (ppenna) merged 1 commit into
feature/nvx-refactorfrom
agents/fix-adapter-sandbox-name-reuse
Nov 10, 2026
Merged

Pedro Henrique Penna (ppenna) merged 1 commit into
feature/nvx-refactorfrom
agents/fix-adapter-sandbox-name-reuse

Conversation

@ppenna

Copy link
Copy Markdown
Contributor

What and why

The Windows/WHP runtime adapter job of run 42896649941 failed while
busy_root_fails_the_teardown created its sandbox, before it launched
anything:

cannot create the busy_root_fails_the_teardown sandbox C:\Windows\SERVIC~1\NETWOR~1\AppData\Local\Temp\ra-2012-3: Access is denied. (os error 5)

Since 07d16d0 (#1432), Sandbox::new names each sandbox ra-PID-N after
the first N that no directory takes, so every test of a binary reuses the
names that the others free. Windows keeps the name of a directory that
remove_dir_all is deleting until the deletion completes, and until then
refuses to create a directory under it with ERROR_ACCESS_DENIED, not
ERROR_ALREADY_EXISTS, which Sandbox::new takes for a failure. The race is
intermittent: the job passed in the six runs of this branch between #1432 and
the failed one.

Each sandbox of a test process now takes N from a process-wide counter, so a
process never takes the name of a sandbox that it created, while a name that
another process left still counts as taken. #1462 fixes dev the same way,
where sandbox names hold the scenario's name, so that only tests that share
one race.

  • tests/runtime-adapter/tests/common/mod.rs: Sandbox::new takes N from
    NEXT_SANDBOX.
  • tests/runtime-adapter/tests/sandbox_names.rs: a new host-only test, which
    boots nothing, drops a sandbox and checks that the next one of the same name
    takes another name. Before the fix, both took ra-45856-0.
  • tests/runtime-adapter/README.md: describes the new test.

A test binary creates a few hundred sandboxes at most, so the counter adds at
most two digits to the short names of 07d16d0: with a seven-digit PID below
/tmp, the longest template store takes 25 of the 55 bytes that its clones'
sockets allow.

Draft pull requests #1442, #1444, #1449, and #1458 carry a copy of
07d16d0, dc669fa, and so race the same way until they rebase onto this
fix.

Validation

On Windows 11 (NTFS), without a hypervisor:

  • Reproduction, with a temporary test that this pull request doesn't add: 8
    threads that create and drop sandboxes through common::Sandbox for 20 s.
    With the Sandbox::new of db39a5d, the run's head, 38 of 10,044 creations
    failed with the run's error; with the fix, 0 of 11,452.
  • cargo test --locked --features host --test sandbox_names, in
    tests/runtime-adapter: failed before the fix, passed after it.
  • At this branch's head, in tests/runtime-adapter, with Rust 1.95.0: cargo fmt --all --check; cargo clippy --locked --all-targets -- -D warnings,
    cargo build --locked, cargo test --locked, and RUSTDOCFLAGS="-D warnings" cargo doc --locked --no-deps, each also with --features host;
    and cargo clippy and cargo doc with --features guest --target x86_64-unknown-linux-musl. With Rust 1.89, cargo check --locked --all-targets, also with --features host. All passed.
  • python scripts/check_test_layout.py and
    python scripts/check_markdown_links.py: passed. This branch has no
    scripts/local_gates.py, so I ran the commands of the actions directly.

Left to CI: the runtime adapter's VM scenarios on Windows/WHP, Linux/KVM, and
Linux/MSHV, including the job that failed; the guest-only build, tests, and
MSRV check on Linux; and the other gates of check-nvx-rs and
validate-nvx.

python scripts/check_test_changes.py --base origin/feature/nvx-refactor
lists one change to an existing test: the Sandbox::new helper in
tests/runtime-adapter/tests/common/mod.rs. It still creates a directory of
its own for each sandbox, skips a name that exists, and panics on any other
error; only its choice of N changed, from the first number that no
directory takes to the next of the process's counter. No assertion, timeout,
or ignored test changed.

The Windows/WHP runtime adapter job of run 42896649941 failed before
busy_root_fails_the_teardown started: Sandbox::new could not create
its sandbox, ra-2012-3, "Access is denied. (os error 5)". Since
07d16d0, which dropped the scenario's name, Sandbox::new names
each sandbox ra-PID-N after the first N that no directory takes, so
each test of a binary takes the names that the others free. Windows
keeps the name of a directory that remove_dir_all deletes until the
deletion completes, and until then refuses to create a directory
under it with ERROR_ACCESS_DENIED, not ERROR_ALREADY_EXISTS, which
Sandbox::new took for a failure: a test that took a name while
another was removing the sandbox of that name panicked. On Windows,
eight threads that create and remove sandboxes so failed 38 of
10,044 creations.

Number the sandboxes of a process from a counter instead, so that a
process never takes the name of a sandbox that it created, and skips
only the names that another process left. On Linux, the counter adds
at most two digits, and with a seven-digit PID the longest template
store below /tmp stays 30 bytes short of the 55 that its sockets
allow.

The new sandbox_names test, which boots nothing, failed before the
change, with the second sandbox at the name of the first.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown
Contributor

This pull request changes existing tests

It modifies or removes 1 existing test asset(s), listed below. Review each with care: a change to a test can hide a regression that the test caught. See doc/contribute.md#changes-to-existing-tests.

Test code

Change What Before After
modified helper fn new in common/mod (tests), impl Sandbox`` tests/runtime-adapter/tests/common/mod.rs:154 tests/runtime-adapter/tests/common/mod.rs:158

Relocated unchanged: 0; added: 5. Compared the merge base eba4c8b6a6a1 with 1ad36e0dde15.

@ppenna
Pedro Henrique Penna (ppenna) merged commit 9298cd7 into feature/nvx-refactor Nov 10, 2026
85 of 87 checks passed
@ppenna
Pedro Henrique Penna (ppenna) deleted the agents/fix-adapter-sandbox-name-reuse branch November 10, 2026 23:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feat-nvx-refactor tests-modified Changes existing tests, test data, or test wiring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant