Improve exception diagnostics for stdio client (#376)

* Improve exception diagnostics for stdio client

Track the last several lines of stderr and include those in an exception created as part of CleanupAsync if the server process has already exited. This is based on an assumption that the server should never exit prior to CleanupAsync being called.

* Address feedback and fix test failure
This commit is contained in:
Stephen Toub 2025-05-14 10:46:49 -04:00 • committed by GitHub
commit c11c634945
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,37 +0,0 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
namespace System.Diagnostics;
internal static class ProcessExtensions
{
public static void Kill(this Process process, bool entireProcessTree)
{
_ = entireProcessTree;
process.Kill();
}
public static async Task WaitForExitAsync(this Process process, CancellationToken cancellationToken = default)
{
if (process.HasExited)
{
return;
}
var tcs = new TaskCompletionSource<bool>();
void ProcessExitedHandler(object? sender, EventArgs e) => tcs.TrySetResult(true);
try
{
process.EnableRaisingEvents = true;
process.Exited += ProcessExitedHandler;
using var _ = cancellationToken.Register(() => tcs.TrySetCanceled(cancellationToken));
await tcs.Task.ConfigureAwait(false);
}
finally
{
process.Exited -= ProcessExitedHandler;
}
}
}