Repository navigation
Commit cd91a89
authored
fix(gateway): frozen worker processes never resume when the host ps stalls (#123976)
* fix(gateway): bound quiescence identity lookups so thaw cannot hang
processIdentity() ran `ps` through execFileSync with no timeout, while its two
siblings in the same script (processes(), processStatus()) both pass
timeout: 2000. Every thaw path gates on it — resumeProcesses(), the watchdog
expiry loop, and REMOTE_WORKSPACE_RESUME_JS all call processIdentity before
each SIGCONT — so a host whose `ps` stalls leaves the entire lease frozen with
no remaining resumer. SIGSTOP cannot be caught, so those processes never run
again and never release their memory.
Bring processIdentity to parity with its siblings.
Measured with the exported scripts against a fixture whose `ps` stalls on the
identity lookup: unbounded resume was still hung when a 20s cap killed it
(exit 124); bounded resume fails in 2s with `spawnSync ps ETIMEDOUT`.
* fix(gateway): thaw frozen processes before retiring the quiescence watchdog
A bounded identity lookup still fails on a stalled host ps. Resume retired the
watchdog first, so an aborted sweep left the lease with no resumer at all and
the frozen workers stopped forever. Thawing first keeps the watchdog as the
recovery owner that clears the lease at expiry; the orphan sweep had the same
inverted order.
* fix(gateway): keep the quiescence watchdog retrying a stalled identity probe
At lease expiry the watchdog ran the same bounded ps lookup and its catch
retired the process on the first ETIMEDOUT, so a stall spanning expiry left the
frozen workers with no resumer at all. It now re-probes on a bounded schedule
and still verifies pid start time before every SIGCONT.
* fix(gateway): make the quiescence ps probes killable so their timeout can fire
execFileSync's timeout only sends killSignal and then waits for the child to
exit, so under the default SIGTERM a ps that ignores it blocked the thaw
forever and the added timeout bounded nothing. All three probes now kill the
stuck child; verified a TERM-ignoring ps returns in ~2s instead of hanging.
* fix(gateway): retire the quiescence watchdog on recovery, not on a retry count
A fixed 150-attempt budget reinstated the permanent freeze for any ps stall
longer than five minutes. The watchdog now backs off up to 60s and keeps
retrying until its sweep completes or the lease file is gone, which is the
condition that actually means the workers no longer need a resumer.
* fix(gateway): thaw before retiring the watchdog in initial quiescence rollback
ClawSweeper on 0162987: the explicit resume path was reordered to thaw
before retiring its watchdog, but the initial quiescence sweep's rollback still
retired first. A bounded identity probe can throw inside resumeProcesses, and by
then the watchdog was already gone, leaving a stopped worker with no remaining
recovery owner and the lease still present.
Apply the same owner-preserving order to the rollback path, so the last resumer
outlives a failed thaw exactly as it does on explicit resume.
Production +3/-1: the resume call moves ahead of the watchdog retirement, plus a
two-line contract comment.
* fix(gateway): harden quiescence recovery after two-phase code review
Review fixes on top of the killable-probe change, from one native pass and two
cold passes:
- The watchdog retried forever on an unparseable lease, leaving an immortal
detached process. The pids to resume live in that file, so retrying cannot
recover them; an unusable lease is now terminal.
- A missing ps binary throws ENOENT too, so the watchdog retired as if the
lease were gone while its workers stayed SIGSTOPped. Only the lease path
retires it now, discriminated on error.path.
- The thaw-first reorder stretched two unlink races. The resume script and the
orphan sweep now tolerate a lease that another owner already removed, so a
fully successful thaw cannot report the sync as failed.
- The stalled-ps recovery test polled 5s against a backoff that doubles to 8s
and never resets; widened to outlast the retry ladder.
Test-file hygiene, required to land lint-clean: the additions pushed
workspace-sync-scripts.test.ts past the repo max-lines cap and introduced two
no-promise-executor-return errors, neither of which fires at the PR base. The
promise executors now use block bodies, and the file is split by subject rather
than suppressed: manifest transaction tests move to workspace-sync-manifest.test.ts,
quiescence tests stay. The moved block is byte-identical and no helper crosses
the boundary.
Proof gap: the gateway vitest project cannot run in this checkout (pre-existing
configureFsSafeNative import failure from stale node_modules), so the split and
the new tests are verified by git comparison, static analysis, oxlint, and
isolated execution of the embedded scripts rather than by a suite run.
* test(gateway): clean up stalled probe watchdog
Restore the healthy process probe after the expected failure, resume the lease, and wait for the detached watchdog to exit so repeated runs do not leak recovery processes.
Co-authored-by: jesse-merhi <[email protected]>
* fix(gateway): clean up failed watchdog startup
* fix(gateway): release empty quiescence leases1 parent b5460ee commit cd91a89
3 files changed
Lines changed: 1042 additions & 773 deletions
File tree
- src/gateway/worker-environments
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| |||
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
31 | 35 | | |
32 | 36 | | |
33 | 37 | | |
| 38 | + | |
| 39 | + | |
34 | 40 | | |
35 | 41 | | |
36 | 42 | | |
| |||
40 | 46 | | |
41 | 47 | | |
42 | 48 | | |
43 | | - | |
| 49 | + | |
44 | 50 | | |
45 | 51 | | |
46 | 52 | | |
| |||
153 | 159 | | |
154 | 160 | | |
155 | 161 | | |
| 162 | + | |
156 | 163 | | |
157 | 164 | | |
158 | 165 | | |
159 | | - | |
160 | | - | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
161 | 169 | | |
162 | 170 | | |
163 | 171 | | |
| |||
171 | 179 | | |
172 | 180 | | |
173 | 181 | | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | | - | |
181 | | - | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
182 | 196 | | |
183 | | - | |
184 | | - | |
185 | 197 | | |
186 | 198 | | |
187 | 199 | | |
| |||
232 | 244 | | |
233 | 245 | | |
234 | 246 | | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
235 | 250 | | |
236 | 251 | | |
237 | 252 | | |
238 | | - | |
239 | 253 | | |
240 | 254 | | |
241 | 255 | | |
242 | 256 | | |
| 257 | + | |
243 | 258 | | |
244 | 259 | | |
245 | 260 | | |
| |||
281 | 296 | | |
282 | 297 | | |
283 | 298 | | |
284 | | - | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
285 | 311 | | |
286 | 312 | | |
287 | 313 | | |
| |||
421 | 447 | | |
422 | 448 | | |
423 | 449 | | |
424 | | - | |
425 | | - | |
426 | | - | |
| 450 | + | |
| 451 | + | |
427 | 452 | | |
428 | 453 | | |
429 | 454 | | |
430 | 455 | | |
431 | | - | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
432 | 467 | | |
0 commit comments