Fix stderr event loss due to missing WaitForExit in DisposeProcess (#1280)

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 16:33:09 -05:00 • committed by GitHub
commit 1dd06e73dc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -227,6 +227,18 @@ public sealed partial class StdioClientTransport : IClientTransport
// and Node.js does not kill its children when it exits properly.
process.KillTree(shutdownTimeout);
}
// Ensure all redirected stderr/stdout events have been dispatched
// before disposing. Only the no-arg WaitForExit() guarantees this;
// WaitForExit(int) (as used by KillTree) does not.
// This should not hang: either the process already exited on its own
// (no child processes holding handles), or KillTree killed the entire
// process tree. If it does take too long, the test infrastructure's
// own timeout will catch it.
if (!processRunning && HasExited(process))
{
process.WaitForExit();
}
}
finally
{