Skip to content

fix: answer a process tree ended only once every process it ran has let go of what it held - #1872

Merged
yansfil merged 4 commits into
mainfrom
fix/windows-tree-end
Oct 30, 2026
Merged

yansfil merged 4 commits into
mainfrom
fix/windows-tree-end

Conversation

@yansfil

@yansfil yansfil commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

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_alive waits 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

  • 운영자 결정 (2026-10-30): the kernel's completion-port queue is owned by Windows and has no limit Hide can set; it is accepted as a known limit, not capped. One thread per hided/hide process (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.md records the same.
  • 조심해서 볼 파일:
    • hide-platform/src/process.rs Followed::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.rs Members, 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.rs capture_until, capture_run, Unix tree_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.rs Windows is_alive - a failed wait or exit-code read keeps the process counted and logs process.alive_unconfirmed.
  • 비용 검토: every notice costs one port read and at most two zero-timeout waits on held processes, however many are held. A process joining a job adds one OpenProcess, one IsProcessInJob and 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.
  • 질문: Microsoft does not guarantee job notices arrive; a missing one leaves the end owed until the caller's deadline (never confirmed). Is that the outcome you want, rather than an immediate error?

Evidence

  • 확인한 것:
    • The earlier form of this change ran in fix: end six crate flakes from product budgets, inherited git settings and a Windows Node warm-up #1863: Windows OS contract 256/256 first try with the signal-based 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_after and a_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.
    • CI on 30b4409 (run 41016473655) green on every lane: Windows OS contract 260 passed, 5 skipped, with the stop and job-cap tests passing on the first try.
    • Local macOS: hide-platform 310 passed, 2 skipped; clippy --all-targets -D warnings clean for hide-platform on macOS and on the Windows target (x86_64-pc-windows-msvc), with the new Windows test compiled.
    • The race test failed 5 of 8 local macOS runs before the second group signal (a holder forked during the kill kept running); after it, 22/22 in fix: end six crate flakes from product budgets, inherited git settings and a Windows Node warm-up #1863 and 10/10 here under load.
  • 확인하지 못한 것:
    • Windows and Linux run only on this PR's CI; this Mac cannot run them.
    • a_capture_waits_for_a_holder_started_while_the_tree_ran_and_one_that_ended_before_its_end orders 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.
    • A lost job notice, a refused hold and a process whose handles take long to close are not driven end to end; the rotation is proved with event objects standing in for process objects.
    • The kernel queue's growth under heavy process churn was not measured.

…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.
@yansfil
yansfil merged commit 7263f24 into main Oct 30, 2026
35 checks passed
@yansfil
yansfil deleted the fix/windows-tree-end branch October 30, 2026 07:42
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.

1 participant