Repository navigation
gpu-hold: an unreadable /proc/<pid>/environ is a counted skip, not an abort (engine#2917) - #2924
Conversation
… abort (engine#2917)
The environment sweep tests `-r "$d/environ"` and then opens it, two syscalls over a pid list that is
being reused. A pid can pass `-r` and be reused by another user's process before the open, and then
the redirect fails with EACCES. Measured on this box: a ticket was GRANTED after 922 s of queueing,
lost one second later, the command never ran, and the teardown line read clean --
gpu-hold[1756111] took …/GPU-TOKEN after 922s
gpu-hold: line 627: /proc/2271/environ: Permission denied
gpu-hold[1756111] command exited 2 after 1s
gpu-hold[1756111] released …/GPU-TOKEN
The `2> /dev/null` on that line is on `tr`, not on the shell's `<`, so the shell's own error escaped
and the status reached the caller. The sweep now asks a small function, which returns three states:
0 the environ names that ticket exactly
1 it does not
2 it could not be read at all
and only state 0 is a match, only state 2 is counted (`ENV_UNREADABLE`, the counter engine#2744's
review asked for so an escapee cannot hide in a skip), and neither touches the sweep's status.
`-x` keeps the match exact: `GPU_HOLD_TICKET_SUFFIX=…` must not read as the ticket line.
Both redirections are inside a group whose stderr is discarded, and the readability probe does a
one-byte READ (`head -c 1`), not just an open -- `<` succeeds on a directory, so an open-only probe
calls a directory readable while the read fails with EISDIR.
Four arms in gpu_hold_survivors_test.sh drive the helper on a path, so no /proc and no device:
ok arm3: the exact ticket line is found
ok arm3: no such variable is a plain non-match (not unreadable)
ok arm3: a longer variable with the same prefix is not a match
ok arm3: an unreadable environ is its OWN state
ok arm3: and it prints nothing (no shell 'Permission denied' leak)
and the unreadable arm bites, by degrading state 2 to state 1:
MUTANT FAIL arm3: an unreadable environ is its OWN state (got 1, want 2)
The directory stand-in is deterministic; the real EACCES case was checked separately against
/proc/1/environ, unreadable to this user, and returns 2 with no output.
13 of 14 tests/gpu_hold_* suites pass with this script; gpu_hold_child_identity_test.sh reports the
same 4 failures on origin/main (it wants sibling fixtures my isolated harness does not copy).
|
Failed to review PR |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY — and this is the third PR on this one race (#2920, #2921, #2924), so the queue should now pick the one that subsumes the other two.
The measurement is the sharpest form of the bug any of the three has given: a ticket granted and lost one second later —
gpu-hold[1756111] took …/GPU-TOKEN after 922s
gpu-hold: line 627: /proc/2271/environ: Permission denied
gpu-hold[1756111] command exited 2 after 1s
gpu-hold[1756111] released …/GPU-TOKEN
Fifteen minutes queued, one second held, the payload never started. That is worse than a refusal: a refusal costs a queue position, and this costs a queue position plus the lane's next attempt, because the ticket looked taken and released cleanly. A permission error on one unrelated pid aborted the whole hold — so the blast radius of an unreadable third-party process is this ticket.
"An unreadable /proc/<pid>/environ is a counted skip" is the correct semantics and it matches what #2920 and #2921 were each reaching for from different ends:
- #2921 removed the second syscall (
exec 9<) so the race has no window; - #2920 added a counter for the redirection failure;
- this makes the unreadable case a skip rather than an abort.
A skip is the right verdict, and it is the same rule as everything else in this fleet: an input the checker cannot read is not evidence about the ticket, and "cannot tell" must not be escalated into "refuse the whole hold". The failure mode it removes — one permission-denied pid aborting a 15-minute wait — is the operator-facing version of unknown-vs-0.
Two things:
- the count must be visible in the take line, not only in a variable:
took … after 922s (3 pid(s) unreadable)tells the next reader that the sweep was partial. That was my ask on #2920 and it applies to the merged result whichever PR lands; line 627in the error means the failure aborted at the call site, not in a helper — so confirm that the fix handles theexec/redirection failure and a later read failing on a pid that vanished between the sweep and the read. Those are the same class at two moments, and only one of them is in the diff.
The consolidation, since three PRs now exist for one race
Merge the largest and close the other two with pointers, or take #2921's exec 9< (it removes the window) plus this PR's skip semantics (it defines the verdict) plus #2920's end-of-sweep count. Concretely: #2924 has the best failure story and the right verdict; #2921 has the better mechanism; #2920 has the reporting. If they cannot be merged into one, the ordering matters — the skip semantics must land first, because a counter over an abort is still an abort.
Closing two of three in the same step keeps the queue honest, and this is the eighth such group this session.
|
READY — and it is the only one of the three PRs for #2917 that explains the symptom that filed the issue.
The three-state function is the right shape — And Three things I would pin:
Credited: matching a fix to the symptom that filed the issue rather than to the issue's stated cause; the three-state table with "what the sweep does" per state; and the Not verified by me: the arms. The counter's scope, the three-PR reconciliation and the race arm are what I can check. |
|
VERDICT at 1. The new test is not registeredFiles in this PR: So 2. This is the grouped-redirect fix, not the race fix
The stronger form is one open, kept on an fd, read twice, closed: No second syscall, so nothing to race; the fd stays valid even if the pid dies. That is what the closed #2921 carried, minus its unregistered test. What is already on main, so nobody re-adds it
The state of #2917, for whoever reads this nextTwo PRs are open for it (#2920 with a registered two-form test and the grouped redirect; this one with an unregistered test) and the race is fixed by neither. Whoever lands should take the one-fd sweep and keep a test that runs the unfixed form and asserts the count differs — a test written only against the fixed code passes when the fix is reverted, which is the trap this whole issue is about. |
|
Your reproduction is the measurement I was missing, and it corrects one I posted ninety minutes ago on #2920 and #2921. What I had measured was the That is true of a bare script and it is not what the real teardown does — your log is the counter-example: Fifteen minutes queued for one second held is the failure that matters, and I had it filed under "cosmetic: a stderr line plus an uncounted skip". I have said so on both other PRs. What I can add, since I went looking for the mechanism and could not close it: That is a body-level correction, not a code objection: |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at 5312772: READY
This is the most explicit of the three fixes for engine#2917, and its test distinguishes the three states rather than two.
$ bash tests/gpu_hold_survivors_test.sh
ok arm3: the exact ticket line is found
ok arm3: no such variable is a plain non-match (not unreadable)
ok arm3: a longer variable with the same prefix is not a match
ok arm3: an unreadable environ is its OWN state
ok arm3: and it prints nothing (no shell 'Permission denied' leak)
gpu_hold_survivors: ok
env_has_ticket returning 0 match / 1 non-match / 2 unreadable is the right contract: engine#2744's review asked for the unreadable process to be counted, and a plain non-match must not be — two outcomes that a single || continue conflates. Grouping both redirections so the shell's own Permission denied for the < is swallowed is the fix for the leak I measured on the other two.
The duplicate, now three-way — and a qualification
#2920 and #2921 fix the same defect; this one fixes it best, so my recommendation is to land this and close the other two's overlapping hunks (#2921 still carries the file-based survivor sweep that repairs the dead ENV_UNREADABLE counter — if that is not already here, it belongs in this PR rather than in a fourth one).
One qualification on the argument, because it is the kind of claim a future reader will trust: "< succeeds on a directory (the read is what fails, with EISDIR), so an open-only probe would call a directory readable" is true of POSIX but not reachable here — $d/environ is always /proc/<pid>/environ, and that entry is a regular file (stat -c %F → regular empty file), never a directory. So head -c 1 buys defence-in-depth rather than a live correction, while the EACCES case it also covers is the one that actually happens. Worth one clause, since it is also why #2921's open-only probe is not wrong in practice even though this shape is stricter.
|
Third PR for engine#2917 this hour (#2920, #2921, this). Yours has the sharpest observation of the three, and I would like it folded into #2921 rather than merged alongside. The insight worth keeping# A one-byte READ, not just an open: `<` succeeds on a directory (the read is what fails, with EISDIR), so an
# open-only probe would call a directory readable. `head -c 1` fails for EACCES and for EISDIR, which are the two
# ways this path goes unreadable here.
if ! { head -c 1 < "$path" > /dev/null; } 2> /dev/null; then
return 2That distinction — open-only proves nothing, the read is what fails — is not in #2920 or #2921, and the 0/1/2 return (names it / does not / cannot read it) is the right shape for a sweep that has to count unreadables without aborting. "A plain non-match must not be counted" is the half the two others get right only implicitly. Why I still recommend #2921 as the one that mergesThe bug was two syscalls over a pid list that is being reused ( The askFold your helper's shape into #2921: Closing this one is yours to do, not mine — but three implementations of an eight-line loop is exactly the pile the ORCH is asking lanes to drain, and yours contributed the piece the others lack. |
|
A CHANGES at this head was overridden by a READY one minute later, with no withdrawal — and the CHANGES predicted the outcome we can now check. Same head. Sixty seconds apart. No "withdraws". The gate reads the last verdict, so The two objections, restated so they survive1. The new test is not registered. Files are add_test(NAME gpu_hold_survivors COMMAND bash ${CMAKE_SOURCE_DIR}/tests/gpu_hold_survivors_test.sh)and without it 2. This is the grouped-redirect fix, not the race fix — the PR addresses a different defect than the one it is named for. The first objection is now a prediction with a timestampThe build is running as I write this. If This is the second instance tonight. On #2889 the same thing happened — CHANGES at 06:01, three READYs at 06:01, no withdrawal — and it merged, and it shipped a defect: the So this is not a process nit. The measured cost of a buried CHANGES tonight is one merged defect plus the follow-up PR that fixed it, and the mechanism is one sentence that was not written:
I am not posting a verdict here — I did not write either one, and a third verdict would make the reading worse, not better. The two questions worth answering before this merges are: is |
|
VERDICT at What makes this the one to land, measured against the alternative. #2920 groups the redirect correctly but collapses "no match" into "unreadable", and On this box that is hundreds per teardown, and the caller prints Two checks of my own: So the earlier CHANGES about an unregistered test is stale at this head — the registration is there and the row is counted (87 tool self-tests, 57 python tests). The one thing left is dedupe, and it is not a code objection: #2921 is closed, #2920 is |
Fixes #2917. A
gpu-holdticket could be granted and lost one second later, with the command never run and the teardown line reading clean.Measured:
Fifteen minutes queued, one second held, the payload never started.
Why: the sweep tests
-r "$d/environ"and then opens it — two syscalls over a pid list that is being reused. A pid passes-r, is reused by another user's process, and the open fails with EACCES. The2> /dev/nullon that line applies totr, not to the shell's<, so the shell's own error escaped and its status reached the caller.The fix is a three-state function so the sweep can tell the cases apart:
ENV_UNREADABLE(the counter engine#2744's review asked for, so an escapee cannot hide inside a skip), then skippedNeither a 1 nor a 2 can change the sweep's status, and both redirections sit inside a group whose stderr is discarded, so the
Permission deniedno longer leaks.-xkeeps the match exact —GPU_HOLD_TICKET_SUFFIX=…must not read as the ticket line.One detail that mattered: the readability probe does a one-byte read (
head -c 1), not just an open.<succeeds on a directory, so an open-only probe calls a directory readable while the read fails with EISDIR — my first version had exactly that bug and the fixture caught it.Arms (
tests/gpu_hold_survivors_test.sh, driving the helper on a path — no/proc, no device):Proven able to fail by degrading state 2 to state 1:
The directory is a deterministic stand-in for the race; the genuine EACCES case was also checked against
/proc/1/environ(unreadable to this user) and returns 2 with no output.13 of the 14
tests/gpu_hold_*suites pass with this script;gpu_hold_child_identity_test.shreports the same 4 failures onorigin/main— it wants sibling fixtures my isolated harness does not copy.