Repository navigation
fix(platform): reap a session child by pid instead of sweeping every child - #7718
Merged
Merged
Conversation
…child `reap_finished_children` swept with `waitpid(-1, .., WNOHANG)` and returned only a count. Wiring that into the accept loop - which is exactly what the comment at connection.rs:314 pointed a future reader at - would have been a latent defect, for two independent reasons. It steals other children's statuses. The daemon forks children that are not sessions: the `name converter` helper, the pre-/post-transfer `exec` hooks and the authentication helper, all owned by `std::process::Child` and reaped through its own `wait`. A bulk sweep in the accept loop races those owners, and the loser gets ECHILD - a helper whose exit code the daemon reads would silently stop being observable. And a count cannot release a slot. #7715 made the `max connections` guard parent-owned and #7716 made reaping the act that drops it, so the parent has to learn WHICH worker ended, not how many did. Both dissolve if the pid is a parameter: try_reap(child_pid) -> Result<Option<ChildEnd>> wait_for_child(child_pid) -> Result<ChildEnd> That pair is deliberately the same shape as the `SessionWorker::try_reap` / `wait` pair #7716 introduced, so the fork backing can slot in under the existing seam. `ChildEnd` stays process vocabulary - Exited or Signalled - because what a non-zero exit means for a *session* is the daemon's decision, not this module's. Under fork, `Died` becomes a fatal signal rather than an escaped panic, which is why the two layers must not share one enum. upstream: socket.c:676-684 `sigchld_handler()` does use `waitpid(-1, ..)`, but passes a NULL status pointer - it discards the outcome, so it has nothing to lose to a race. oc reports session outcomes, so it needs the status and therefore the narrower call. `wait_for_child` resumes on EINTR. That is not the retry/backoff this repo bars: the syscall never completed and nothing is being backed off. A daemon with signal handlers installed sees it routinely. Still no production caller - the module remains staged for FORK-EPIC F2b step 2. The change is that the API it stages is now the one that step can safely use, and the footgun is gone rather than waiting to be picked up.
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.
FORK-EPIC F2b, step 2 groundwork.
session_forkis staged for the fork-backed session and has zero production callers; this replaces the one primitive in it that a future caller could not safely use.The bulk reaper was a latent defect waiting for a caller
reap_finished_childrenswept withwaitpid(-1, .., WNOHANG)and returned a count.connection.rs:314pointed the next reader straight at it — "under a forked backing this is also wherereap_finished_childrenbelongs" — and wiring it there would have been wrong twice over.It steals other children's statuses. The daemon forks children that are not sessions: the
name converterhelper, the pre-/post-transferexechooks, the auth helper. Those are owned bystd::process::Childand reaped by its ownwait. A bulk sweep in the accept loop races those owners, and the loser getsECHILD— a helper whose exit code the daemon reads would silently stop being observable.And a count cannot release a slot. #7715 made the
max connectionsguard parent-owned and #7716 made reaping the act that drops it, so the parent must learn which worker ended, not how many did.Both dissolve if the pid is a parameter:
Deliberately the same shape as the
SessionWorker::try_reap/waitpair from #7716, so a fork backing slots in under the existing seam.ChildEndstays process vocabulary —ExitedorSignalled— because what a non-zero exit means for a session is the daemon's decision. Under fork,SessionOutcome::Diedbecomes a fatal signal rather than an escaped panic; that is exactly why the two layers must not share one enum.upstream:
socket.c:676-684sigchld_handler()does usewaitpid(-1, ..)— but with a NULL status pointer. It discards the outcome, so it has nothing to lose to a race. oc reports session outcomes, so it needs the status and therefore the narrower call.Non-vacuity
a_running_child_is_not_reaped_and_a_killed_one_reports_its_signalcarries two claims a single-outcome stub fails: a child that has not ended reportsNone, and a killed one reportsSignalledrather than a clean exit. Without it, atry_reaphard-wired toSome(Exited(0))satisfies every other assertion in the module.Mutation-proven —
0 => Ok(None)changed to0 => Ok(Some(ChildEnd::Exited(0))):The two that stay green are the negative controls:
fork_session_splits_parent_and_childandtry_reap_refuses_a_pid_that_is_not_our_child.That last one is the whole safety argument in a test: a pid that is not ours is an error, never a fabricated outcome (
ECHILD).One deliberate loop
wait_for_childresumes onEINTR. That is not the retry/backoff this repo bars — the syscall never completed and nothing is being backed off. A daemon with signal handlers installed sees it routinely.Verification
On the pinned 1.88.0 toolchain, not stable (the toolchain mismatch was the shipping defect in #7655):
cargo fmt -p platform -- --checkclean — ⚠ my first check reportedFMT=0from a| tailpipeline; that was tail's exit code and rustfmt was actually failing. Re-run without the pipe: real rc 1, oneassert_eq!reflowed, now clean.clippy --workspace --all-targets --all-features --no-deps -D warningscleannextest -p platform session_fork4/4Scope
Still no production caller — the module stays staged. What changes is that the API it stages is now one that step 2 can safely use, and the footgun is gone rather than waiting to be picked up. The
connection.rscomment is retargeted to say per-pid, one call per worker the parent owns, never a bulk sweep.