Commit 9681eca
authored
fix: avoid PTY wait deadlock on wait errors (#165)
## Summary
- Fix the PTY wait deadlock by ensuring the child-monitor thread always
sets the shared completion slot, including wait failures.
- Store wait failures as `Arc<std::io::Error>` in the shared `OnceLock`
(`Result<ExitStatus, Arc<std::io::Error>>`) so error state is shareable
without synthetic fallback status.
- Change `ChildHandle::wait()` to return `anyhow::Result<ExitStatus>`
and propagate wait failures through callers.
- Update downstream helpers/callers (`pty_terminal_test`, milestone
tests, and `vite_task_bin` e2e harness) to consume the new
`anyhow::Result` return type.
- Keep PTY integration tests strict at `#[timeout(5000)]` and run them
without a Windows serialization guard.
## Stable Reproduction (before fix)
To deterministically reproduce the real deadlock path (without mocking
`child.wait()` return values), I used a temporary Windows-only repro
patch that swaps the internal `WinChild` process handle with a
non-process handle (`CreateEventW` event handle). This makes
`child.wait()` execute the real Windows wait/get-exit-code path and
return `Err`.
With the old code path (`if let Ok(status) = child.wait() { ... }`),
`OnceLock` was never set on error, and `ChildHandle::wait()` blocked
forever.
Repro command:
```bash
cargo xtest --builder cargo-xwin --target x86_64-pc-windows-msvc -p pty_terminal --test terminal -- read_to_end_returns_exit_status_nonzero
```
Observed behavior under repro:
- timed out at ~15s with `#[timeout(15000)]`
- timed out again at ~60s with `#[timeout(60000)]`
That demonstrates timeout-independent deadlock behavior.
## Why this fixes it
- Background monitor thread now always sets the shared wait result (`Ok`
or `Err`).
- `ChildHandle::wait()` cannot block forever on an unset `OnceLock`.
- Wait failures are preserved and surfaced as real errors (no synthetic
`ExitStatus::with_exit_code(1)`).
## Validation
- `cargo clippy -p pty_terminal --all-targets --all-features -- -D
warnings`
- `cargo test -p pty_terminal -p pty_terminal_test`
- `cargo test -p vite_task_bin --test e2e_snapshots --no-run`
- `cargo xtest --builder cargo-xwin --target x86_64-pc-windows-msvc -p
pty_terminal --test terminal`
- `cargo xtest --builder cargo-xwin --target aarch64-pc-windows-msvc -p
pty_terminal --test terminal`
- `cargo xtest --builder cargo-xwin --target x86_64-pc-windows-msvc -p
pty_terminal --test terminal` repeated 40 times (all green, without
serial guard)1 parent 379efcd commit 9681eca
File tree
5 files changed
+29
-20
lines changed- crates
- pty_terminal_test
- src
- tests
- pty_terminal
- src
- tests
- vite_task_bin/tests/e2e_snapshots
5 files changed
+29
-20
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
| 14 | + | |
13 | 15 | | |
14 | 16 | | |
15 | 17 | | |
| |||
32 | 34 | | |
33 | 35 | | |
34 | 36 | | |
35 | | - | |
| 37 | + | |
36 | 38 | | |
37 | 39 | | |
38 | 40 | | |
| |||
221 | 223 | | |
222 | 224 | | |
223 | 225 | | |
224 | | - | |
225 | | - | |
226 | | - | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
227 | 235 | | |
228 | 236 | | |
229 | 237 | | |
| |||
263 | 271 | | |
264 | 272 | | |
265 | 273 | | |
266 | | - | |
| 274 | + | |
267 | 275 | | |
268 | 276 | | |
269 | 277 | | |
270 | 278 | | |
271 | 279 | | |
272 | 280 | | |
273 | | - | |
274 | | - | |
275 | | - | |
276 | | - | |
| 281 | + | |
277 | 282 | | |
278 | 283 | | |
279 | 284 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
| 23 | + | |
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
50 | | - | |
| 50 | + | |
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
| |||
98 | 98 | | |
99 | 99 | | |
100 | 100 | | |
101 | | - | |
| 101 | + | |
102 | 102 | | |
103 | 103 | | |
104 | 104 | | |
| |||
119 | 119 | | |
120 | 120 | | |
121 | 121 | | |
122 | | - | |
| 122 | + | |
123 | 123 | | |
124 | 124 | | |
125 | 125 | | |
| |||
165 | 165 | | |
166 | 166 | | |
167 | 167 | | |
168 | | - | |
| 168 | + | |
169 | 169 | | |
170 | 170 | | |
171 | 171 | | |
| |||
346 | 346 | | |
347 | 347 | | |
348 | 348 | | |
349 | | - | |
| 349 | + | |
350 | 350 | | |
351 | 351 | | |
352 | 352 | | |
| |||
362 | 362 | | |
363 | 363 | | |
364 | 364 | | |
365 | | - | |
| 365 | + | |
366 | 366 | | |
367 | 367 | | |
368 | 368 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
94 | 98 | | |
95 | 99 | | |
96 | 100 | | |
97 | | - | |
| 101 | + | |
98 | 102 | | |
99 | 103 | | |
100 | 104 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
70 | | - | |
| 70 | + | |
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
| |||
122 | 122 | | |
123 | 123 | | |
124 | 124 | | |
125 | | - | |
| 125 | + | |
126 | 126 | | |
127 | 127 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
391 | 391 | | |
392 | 392 | | |
393 | 393 | | |
394 | | - | |
| 394 | + | |
395 | 395 | | |
396 | 396 | | |
397 | 397 | | |
| |||
0 commit comments