Repository navigation
WIP: fix #2529 #2539 job entry lifetime - #2568
Merged
Merged
Conversation
…oundary (#2529) GNU marks a job J_NOTIFIED when an operand wait consumes it (jobs.c:3434-3437 wait_for_job, jobs.c:2776-2779 wait_for_single_pid) and deletes DEADJOB && IS_NOTIFIED entries in cleanup_dead_jobs (jobs.c:1303), reached from notify_and_cleanup (jobs.c:3642) at parse.y:2533 read_command and directly at jobs.c:572 stop_pipeline before alloc_job_entry. Rubash had only the wait-internal and listing collection points, so a consumed entry lingered: the next job was numbered [2], `kill %n` on a later line silently succeeded against the corpse, and a bare wait rode out the misnumbered replacement job (adj-signals issue1991/issue2381/issue1604 faces). - JobTable::register_pipeline_stages runs cleanup_dead_jobs before id allocation (stop_pipeline mirror). - refresh_background_jobs_impl runs cleanup_dead_jobs when the reader line/run advanced since the previous refresh (read_command mirror); `;` siblings on one list see no cleanup, matching GNU's retention within a list. Retention of unwaited dead jobs (issue2381/issue2340 contract) is untouched: the predicate still requires Completed && notified. Pins: tests/issue2529_job_lifetime.rs (oracle GNU 5.3.20).
…2539) GNU wait_for (jobs.c:3064) calls waitchld only while the child is recorded RUNNING; for a job recorded STOPPED it returns 128+WSTOPSIG (jobs.c:3255-3257) from the recorded state — warning only for % operands (jobs.c:3409-3410), silent for a pid operand — and never reaps the pending death during that wait. Rubash's wait-entry refresh published the deferred SIGCONT mark and applied the pending death completion before the recorded state was consulted, so a stopped job that was CONT+KILLed answered 137 with a Killed notice where GNU answers 147 silently (cluster-F probe shape). execute_wait_inner now enters through a wait-gated observed refresh: for jobs recorded Stopped, Running marks stay deferred and reap completions (pending or freshly swept) stay stashed until the next ordinary notification point. The existing recorded-Stopped arm then answers 147. wait -n and fg keep the ungated refresh (wait_for(ANY_PID) reaps unconditionally), and a death recorded before the wait still answers 137 + notice. Pins: tests/issue2539_stopped_killed_wait_regressions.rs (oracle GNU 5.3.20).
) GNU wait_for_background_pids' tail (jobs.c:2853-2858): without WAIT_WAITS_FOR_ALL_PROCSUBS (not defined in the oracle build), a bare wait runs procsub_waitpid (jobs.c:1131) on last_procsub_child only when its pid equals last_asynchronous_pid, then delete_procsubs. Rubash tracked no last-procsub pid and its bare wait only swept already-dead fork placeholders, so a live >(…) consumer — a real child in background_children — outlived the wait and its output landed after the next command's (`echo hi > >(sleep 0.3; echo inner); wait; echo done` printed done before inner; GNU prints inner first, and with two procsubs settles only the last). - ShellState::last_procsub_pid recorded at all four procsub spawn sites alongside $! (real output consumer, input producer, both fork-placeholder registrations). - wait_last_procsub_if_last_async: at the bare wait's tail (with-jobs block and no-jobs path), when last_procsub_pid == last_background_pid and the child is live, block on it via wait_for_background_pid; placeholders and already-recorded pids return at once, like procsub_waitpid. Pins: tests/issue2560_bare_wait_procsub_regressions.rs (oracle GNU 5.3.20).
caomengxuan666
force-pushed
the
fix/2529-job-lifetime
branch
from
November 2, 2026 06:35
04074a6 to
29b348b
Compare
caomengxuan666
marked this pull request as ready for review
November 2, 2026 07:37
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.
Refs #2529
Refs #2539
Refs #2560