Skip to content

fix(sandbox): fix data corruption in sync --down and hang in sync --up#93

Merged
pimlock merged 3 commits intomainfrom
fix/sandbox-sync-data-ordering
Mar 4, 2026
Merged

fix(sandbox): fix data corruption in sync --down and hang in sync --up#93
pimlock merged 3 commits intomainfrom
fix/sandbox-sync-data-ordering

Conversation

@pimlock
Copy link
Copy Markdown
Collaborator

@pimlock pimlock commented Mar 4, 2026

Summary

  • sync --down corruption: The sandbox SSH server used tokio::spawn fire-and-forget for each stdout/stderr chunk, which provided no ordering guarantee under tokio's work-stealing scheduler. Under load, chunks arrived out-of-order, corrupting tar streams. Replaced with runtime.block_on() to ensure sequential delivery.
  • sync --up hang: SshHandler never implemented channel_eof. Without it, the child process stdin was never closed when the client signaled EOF, so cat | tar xf - waited indefinitely. Added channel_eof handler that drops the input sender.
  • Shell completion: Added ValueHint::AnyPath to the --up argument for shell path completion.

Test Plan

  • Added Rust unit tests verifying that dropping the mpsc sender (the mechanism channel_eof uses) closes the child's stdin pipe and delivers all buffered data before EOF. Tests use a 5s timeout and would hang without the fix.
  • Added a 512 KiB large-file round-trip to the E2E bash sync test with SHA-256 checksum verification. Small test files fit in a single SSH chunk and cannot trigger the data ordering bug.
  • cargo test -p navigator-sandbox passes (169 tests).
./e2e/bash/test_sandbox_sync.sh
==> Creating sandbox with sleep infinity
==> Waiting for sandbox to be ready
==> Sandbox created: sandbox-25657701-d746-4a6e-9ac8-3cd887c11bb0
==> Preparing local test files
==> Syncing local directory up to sandbox
==> Syncing files back down from sandbox
==> Verifying downloaded files
==> greeting.txt verified
==> subdir/nested.txt verified
==> Generating large test file (~512 KiB)
==> Syncing large file up to sandbox
==> Syncing large file back down
==> Large file round-trip verified (SHA-256 match, 524288 bytes)
==> Testing single-file sync
==> Single-file round-trip verified
==> Stopping sandbox create (pid 64297)
==> Deleting sandbox sandbox-25657701-d746-4a6e-9ac8-3cd887c11bb0
✓ Deleted sandbox sandbox-25657701-d746-4a6e-9ac8-3cd887c11bb0
==> PASS

@pimlock pimlock self-assigned this Mar 4, 2026
pimlock added 2 commits March 4, 2026 00:00
The sandbox SSH server used tokio::spawn fire-and-forget for each stdout/stderr
chunk, which provided no ordering guarantee under tokio's work-stealing scheduler.
Under load, chunks arrived out-of-order, corrupting tar streams during download.

Replace tokio::spawn with runtime.block_on() to ensure each chunk is fully sent
before reading the next. Remove AsyncWriteExt::shutdown() from the SSH proxy's
copy helper to prevent gateways from treating TCP half-close as full-close and
truncating in-flight downloads.

Implement channel_eof handler on the sandbox SSH server to close the child
process stdin when the client signals EOF. Without this, commands like
'cat | tar xf -' used by sync --up would hang waiting for stdin EOF
indefinitely. Add ValueHint::AnyPath to the --up argument for shell completion.

Signed-off-by: Piotr Mlocek <pmlocek@nvidia.com>
Add Rust unit tests verifying that dropping the mpsc sender (the mechanism
channel_eof uses) closes the child's stdin pipe and delivers all buffered
data before EOF. These tests would hang without the channel_eof fix.

Add a 512 KiB large-file round-trip to the E2E sync bash test with SHA-256
checksum verification. Small test files fit in a single SSH chunk and cannot
trigger the data ordering bug that corrupted tar streams.

Signed-off-by: Piotr Mlocek <pmlocek@nvidia.com>
@pimlock pimlock force-pushed the fix/sandbox-sync-data-ordering branch from eaa2c07 to 2f2edad Compare March 4, 2026 08:00
@pimlock pimlock requested a review from drew March 4, 2026 08:40
@pimlock pimlock merged commit 2d07e02 into main Mar 4, 2026
9 checks passed
@pimlock pimlock deleted the fix/sandbox-sync-data-ordering branch March 4, 2026 16:35
drew pushed a commit that referenced this pull request Mar 16, 2026
#93)

The sandbox SSH server used tokio::spawn fire-and-forget for each stdout/stderr
chunk, which provided no ordering guarantee under tokio's work-stealing scheduler.
Under load, chunks arrived out-of-order, corrupting tar streams during download.

Replace tokio::spawn with runtime.block_on() to ensure each chunk is fully sent
before reading the next. Remove AsyncWriteExt::shutdown() from the SSH proxy's
copy helper to prevent gateways from treating TCP half-close as full-close and
truncating in-flight downloads.

Implement channel_eof handler on the sandbox SSH server to close the child
process stdin when the client signals EOF. Without this, commands like
'cat | tar xf -' used by sync --up would hang waiting for stdin EOF
indefinitely. Add ValueHint::AnyPath to the --up argument for shell completion.
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.

2 participants