Skip to content

Commit c564746

Browse files
committed
Add parent death detection to worker process
1 parent fd1efaf commit c564746

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/Asynkron.TestRunner.Worker/Program.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,26 @@
1515
cts.Cancel();
1616
};
1717

18+
// Monitor parent process - exit if stdin closes (parent died)
19+
_ = Task.Run(async () =>
20+
{
21+
try
22+
{
23+
while (!cts.IsCancellationRequested)
24+
{
25+
// Peek at stdin - if parent died, this returns -1 immediately
26+
var peek = Console.In.Peek();
27+
if (peek == -1 && Console.IsInputRedirected)
28+
{
29+
// Parent died, exit immediately
30+
Environment.Exit(0);
31+
}
32+
await Task.Delay(500, cts.Token);
33+
}
34+
}
35+
catch { /* ignore */ }
36+
});
37+
1838
await RunWorkerAsync(Console.In, Console.Out, frameworks, cts.Token);
1939

2040
static async Task RunWorkerAsync(

0 commit comments

Comments
 (0)