fix: launch external background jobs before shell exit#1139
Draft
cataggar wants to merge 2 commits into
Draft
Conversation
Spawn simple external background commands before returning from the async separator path so short-lived shells do not drop them when the runtime exits. Keep compound background subshells documented as a follow-up. Assisted-by: GitHub Copilot Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Performance Benchmark Report
Code Coverage Report: Only Changed Files listed
Minimum allowed coverage is Test Summary: bash-completion test suite
|
Self-review follow-ups for the launch-before-exit fix.
Replace the hand-curated metacharacter scan in is_plain_command_name
with parser-backed checks that delegate to the single source of truth:
* brush_parser::word::parse for quoting / parameter / command /
arithmetic / tilde expansion and escape sequences;
* brush_parser::word::parse_brace_expansions, inspecting for an
actual BraceExpressionOrText::Expr piece (the parser wraps any
non-empty input in Some, so a naive Some(_) check would reject
every literal name);
* brush_parser::pattern::pattern_has_glob_metacharacters for
pathname expansion, honoring the live extglob option.
Also reject names containing any character that the current IFS would
split on, so a custom IFS like '/' can't make the fast path execute
'/bin/echo' verbatim while the regular path would have split it into
multiple fields.
Add rustdoc to all of the new helpers introduced in reubeno#1139
(start_background_ao_list, background_job_params,
is_simple_external_background_candidate, is_plain_command_name, the
*_has_deferred_expansion family) so the rationale for each step of the
fast-path eligibility check is documented.
Add unit tests covering literal names, quoting, expansions, brace
expressions vs single-element {…}, glob metacharacters,
extglob-sensitivity, and the IFS-aware splitting check.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
Made by GitHub Copilot.
Summary
-c/stdin shell invocations do not drop them when brush exits.wait/job-manager behavior without adding an implicit wait on shell exit.Manual testing
Before the fix:
cargo build --package brush-shell --quiet.target/debug/brush --norc --noprofile --no-config --disable-color -c 'touch bg_done &', slept briefly, and confirmedbg_donewas missing.bash --norc --noprofile -c 'touch bg_done &', slept briefly, and confirmedbg_donewas present.bash --norc --noprofile -c 'sleep 1 &'and confirmed bash returned immediately (~0.008s).After the fix:
bg_doneis present.target/debug/brush --norc --noprofile --no-config --disable-color -c 'sleep 1 &'and confirmed brush returns immediately (~0.023s).Automated testing
cargo test --package brush-shell --test brush-compat-tests -- "without explicit wait" --nocapturecargo test --package brush-shell --test brush-compat-tests -- "does not delay shell exit" --nocapturecargo test --package brush-shell --test brush-compat-tests -- "Background jobs::" --nocapturecargo xtask ci quickcargo-nextestwas not installed in this environment.cargo-nextest0.9.133.cargo nextest run --workspace --no-fail-fast -E 'not binary(brush-compat-tests) and not binary(brush-interactive-tests) and not binary(brush-completion-tests)'cargo test --workspace --exclude brush-fuzz --lib --bins --examples --no-fail-fastManual verification steps
cargo build --package brush-shell --quiet.-csurvives shell exit:repo=$(pwd); tmp=$(mktemp -d); (cd "$tmp" && "$repo/target/debug/brush" --norc --noprofile --no-config --disable-color -c 'touch bg_done &'); sleep 0.2; test -f "$tmp/bg_done".repo=$(pwd); tmp=$(mktemp -d); (cd "$tmp" && printf 'touch bg_done &\n' | "$repo/target/debug/brush" --norc --noprofile --no-config --disable-color); sleep 0.2; test -f "$tmp/bg_done".time target/debug/brush --norc --noprofile --no-config --disable-color -c 'sleep 5 >/dev/null 2>&1 &'.cargo test --package brush-shell --test brush-compat-tests -- "Background jobs::" --nocapture.Addresses #1079.