Commit 35f56e6
Ian Tay
·
2026-03-08 12:57:26 -0400 EDT
parent 2d37a09
fix(wait): time out after 3 polls if no matching sessions are found Follow-up to the upstream wait fix: the `total > 0` guard prevented vacuous exit 0, but left a typo'd `zmx wait foo` polling forever — trading a wrong answer for no answer. After 3 iterations (~3s) with max_seen still at 0, exit 2 with "no matching sessions found". 3s is generous: `zmx run foo && zmx wait foo` is essentially sequential (run blocks until the socket exists and the Run IPC is acked), so a persistent zero is a typo, not slowness.
1 files changed,
+16,
-1
+16,
-1
| ... | ... | @@ -650,8 +650,9 @@ fn wait(cfg: *Cfg, session_names: std.ArrayList([]const u8)) !void { | |
| 650 | 650 | ||
| 651 | 651 | // Highest match count seen so far. Lets us distinguish "sessions haven't | |
| 652 | 652 | // appeared yet" (keep polling) from "sessions we were tracking | |
| 653 | - | // disappeared" (fail — daemon crashed or was killed). | |
| 653 | + | // disappeared" (fail -- daemon crashed or was killed). | |
| 654 | 654 | var max_seen: i32 = 0; | |
| 655 | + | var zero_match_iters: u32 = 0; | |
| 655 | 656 | ||
| 656 | 657 | while (true) { | |
| 657 | 658 | var sessions = try util.get_session_entries(alloc, cfg.socket_dir); |
| ... | ... | @@ -706,6 +707,20 @@ fn wait(cfg: *Cfg, session_names: std.ArrayList([]const u8)) !void { | |
| 706 | 707 | return; | |
| 707 | 708 | } | |
| 708 | 709 | ||
| 710 | + | if (max_seen == 0) { | |
| 711 | + | // `zmx run foo && zmx wait foo` is essentially sequential, so | |
| 712 | + | // matching sessions should be visible from the first poll. If | |
| 713 | + | // nothing appears after a few iterations it's almost certainly a | |
| 714 | + | // typo, not a slow start. | |
| 715 | + | zero_match_iters += 1; | |
| 716 | + | if (zero_match_iters >= 3) { | |
| 717 | + | try stdout.print("error: no matching sessions found\n", .{}); | |
| 718 | + | try stdout.flush(); | |
| 719 | + | std.process.exit(2); | |
| 720 | + | return; | |
| 721 | + | } | |
| 722 | + | } | |
| 723 | + | ||
| 709 | 724 | std.Thread.sleep(1000 * std.time.ns_per_ms); | |
| 710 | 725 | } | |
| 711 | 726 | } |