Repository navigation
fix: answer a process tree ended only once every process it ran has let go of what it held - #1872
Merged
Merged
Conversation
…et go of what it held Windows counts a process out of its job and sets its exit code before it closes the handles the process held, so a capture or run returned while a process it had ended, or one that ended on its own, still held a pipe, a file or a folder. Each child's job now announces every process on one completion port that a thread reads for the life of the process; each announced process is held until it is signalled, notices are counted against the job's own count, and a process that could not be followed keeps every later end unconfirmed. is_alive waits on the process object and counts a process whose wait fails. A member still running while the end is confirmed gets the end again; on Unix the leader stays unreaped until then, so the group signal reaches only its own group.
…ixed Joining the notice port and its stop now share one lock, so a job is refused once the port is no longer read and every end of a job followed before answers why at once; a stop takes each job's notices off the port. Held processes are kept by pid, a notice checks at most two exited ones for their signal, and at most 1,024 jobs are followed at once, a child past that refused at its start. The ordered test says what it orders rather than an order inside the system.
Each job notice now checks the next two held processes of the job in turn and puts the ones not yet signalled behind the rest, instead of waiting on the oldest one the job said exited. An ended process behind one whose handles take long to close, or whose exit notice never came, is let go within one turn of them all, so the held cap is reached only by processes that are still running.
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.
Closes with-hide/hide-private#327
Summary
On Windows a capture or run said a process tree had ended while a process in it still held a file, so removing the folder right after was refused.
Windows takes a process off its job's count, and sets its exit code, before it closes what the process held.
Now every process a child's job runs is followed from its start, and the end is answered only once each one has let go;
is_alivewaits for the same signal.On every system, a process the tree starts while it is being ended is ended too; on macOS it used to keep running.
스크린샷 없음: no screen changes.
Review
hide-job-notices) reads every child's job notices from that port for the life of the process, and notices wait in the queue only while the children's processes start and end faster than it reads them. What Hide owns is capped, and crossing a cap is a failure the caller sees: each notice costs the thread a fixed amount of work, at most 1,024 jobs are followed at once (a child past it is refused at its start), and at most 4,096 processes are held per job (past it, every question about that job's end answers with the reason).docs/ARCHITECTURE.mdrecords the same.hide-platform/src/process.rsFollowed::notice,let_go_of_signalled- each notice checks the next two held processes in turn; one not yet signalled goes behind the rest, so a process slow to end holds up no other, and one whose exit notice never came is let go on its turn.hide-platform/src/process.rsMembers,Notices::stop,left_running- failure path: a process that cannot be held, a failed wait, past 4,096 held, or the thread stopping is kept as the reason and every later end answers it; held handles are never dropped on an error. When the thread stops, each job's notices are taken off the port; if the system refuses that for a job, it is only logged (process.job_notices_left_set) and that job's notices keep reaching the unread port.hide-platform/src/process.rscapture_until,capture_run, Unixtree_ended- the leader is reaped only after the tree's end is confirmed, so a second group signal cannot reach a reused group id.hide-platform/src/process.rsWindowsis_alive- a failed wait or exit-code read keeps the process counted and logsprocess.alive_unconfirmed.OpenProcess, oneIsProcessInJoband one wait. Since each held process came with a notice that checked two, checks outpace holds even when exit notices are lost, and every ended process is let go within one turn of the held ones; the owner lets go of all ended ones whenever it asks about the end. The thread blocks on the port and does nothing otherwise.Evidence
is_alive, after the job-count end failed both capture tests every time (runs 40996135782, 40996147032).an_ended_process_is_let_go_behind_one_slow_to_end_without_its_exit_notice(Windows unit test): three held objects not yet signalled ahead of one signalled whose exit notice never comes; the signalled one is let go within one turn while the oldest one's exit is announced over and over, and the slow one is let go once it signals.a_job_followed_before_the_notices_stopped_answers_why_and_none_joins_afteranda_child_past_the_followed_jobs_cap_is_refused_and_an_ended_one_frees_its_place(Windows unit tests, real empty jobs and a port) cover the stop and the job cap.hide-platform310 passed, 2 skipped;clippy --all-targets -D warningsclean forhide-platformon macOS and on the Windows target (x86_64-pc-windows-msvc), with the new Windows test compiled.a_capture_waits_for_a_holder_started_while_the_tree_ran_and_one_that_ended_before_its_endorders the starts and the ending against the end, but when the system closes a handle is its own timing, so the test can pass without the fix too.