Fix flaky stderr test: call WaitForExit() after WaitForExitAsync() to flush ErrorDataReceived events (#1278)

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
This commit is contained in:
Copilot 2026-02-15 09:55:24 -05:00 • committed by GitHub
commit 3caac28a76
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -72,11 +72,13 @@ internal sealed class StdioClientSessionTransport(
try
{
// The process has exited, but we still need to ensure stderr has been flushed.
// WaitForExitAsync only waits for exit; it does not guarantee that all
// ErrorDataReceived events have been dispatched. The synchronous WaitForExit()
// (no arguments) does ensure that, so call it after WaitForExitAsync completes.
#if NET
await _process.WaitForExitAsync(cancellationToken).ConfigureAwait(false);
#else
_process.WaitForExit();
#endif
_process.WaitForExit();
}
catch { }