feat: Add AsyncOpenFile infrastructure and migrate builtins to async I/O#1069
Open
lu-zero wants to merge 3 commits intoreubeno:mainfrom
Open
feat: Add AsyncOpenFile infrastructure and migrate builtins to async I/O#1069lu-zero wants to merge 3 commits intoreubeno:mainfrom
lu-zero wants to merge 3 commits intoreubeno:mainfrom
Conversation
Public API changes for crate: brush-coreRemoved itemsAdded itemsChanged itemsPerformance Benchmark Report
Code Coverage Report: Only Changed Files listed
Minimum allowed coverage is |
24aa365 to
5be0c65
Compare
c34119e to
85643c8
Compare
Introduce AsyncOpenFile and related types to replace synchronous I/O across the shell's file handling. This enables non-blocking I/O for builtins, shell execution, and interactive features. Key changes: - Add AsyncOpenFile enum with tokio-based variants (File, Stdio, Pipe) - Add AsyncStream trait for custom async I/O implementations - Add AsyncOpenFiles wrapper for async file descriptor management - Convert all builtins to use async write_all/flush patterns - Fix signal race in process.wait() by polling for stopped children before entering tokio::select! loop (handles SIGCHLD arriving between SIGCONT and signal listener creation) - Update ExecutionContext with async write helper methods - Update examples to use async I/O patterns
The async I/O refactor caused xtrace (set -x) output lines to appear in a different order than bash on Linux. This happened because each trace_command call cloned AsyncOpenFile::Stderr into a fresh tokio::io::stderr() handle, and Linux's async I/O scheduling could reorder small writes between handles. Fix by using block_in_place + synchronous write on a dup'd FD, matching the original behavior. This ensures trace output ordering is deterministic while keeping the surrounding code async.
block_in_place and try_clone_to_owned are not available on WASM and Windows. Fall back to async write_all + flush on non-unix platforms.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR introduces async file descriptor abstractions (
AsyncOpenFile,AsyncOpenFiles,AsyncStream) and migrates most builtins to use async I/O for better performance with piped/redirected I/O.Infrastructure Changes
AsyncOpenFile: Wraps atokio::fs::Filefor async read/write operationsAsyncOpenFiles: Wrapper for managing async file descriptorsAsyncStream: Trait for async stream operationsstdin_async(),stdout_async(),stderr_async()methods toExecutionParametersandExecutionContextBuiltins Migrated to Async I/O
Pattern Used
Vec<u8>context.stdout_async()if availableTesting
Notes