Skip to content

Commit 1dd06e7

Browse files
Copilotstephentoub
andauthored
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>
1 parent 3caac28 commit 1dd06e7

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/ModelContextProtocol.Core/Client/StdioClientTransport.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,18 @@ internal static void DisposeProcess(
227227
// and Node.js does not kill its children when it exits properly.
228228
process.KillTree(shutdownTimeout);
229229
}
230+
231+
// Ensure all redirected stderr/stdout events have been dispatched
232+
// before disposing. Only the no-arg WaitForExit() guarantees this;
233+
// WaitForExit(int) (as used by KillTree) does not.
234+
// This should not hang: either the process already exited on its own
235+
// (no child processes holding handles), or KillTree killed the entire
236+
// process tree. If it does take too long, the test infrastructure's
237+
// own timeout will catch it.
238+
if (!processRunning && HasExited(process))
239+
{
240+
process.WaitForExit();
241+
}
230242
}
231243
finally
232244
{

0 commit comments

Comments
 (0)