Skip to content

Commit 1a58fd5

Browse files
Copilotstephentoub
andcommitted
Always call WaitForExit() (no args) before Dispose() in DisposeProcess
The previous fix only called WaitForExit() in the else branch (process already exited). But when the process is still running, KillTree is called which uses either Kill+WaitForExit(int) or returns early if the process already exited - neither of which guarantees ErrorDataReceived event dispatch. Move WaitForExit() (no args) to be unconditional after the if/else block so it always runs before Dispose(). Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
1 parent 0a6158f commit 1a58fd5

1 file changed

Lines changed: 5 additions & 7 deletions

File tree

src/ModelContextProtocol.Core/Client/StdioClientTransport.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -227,13 +227,11 @@ internal static void DisposeProcess(
227227
// and Node.js does not kill its children when it exits properly.
228228
process.KillTree(shutdownTimeout);
229229
}
230-
else
231-
{
232-
// The process has already exited. Call WaitForExit() (no arguments)
233-
// to ensure all redirected stderr/stdout events have been dispatched
234-
// before disposing.
235-
process.WaitForExit();
236-
}
230+
231+
// Ensure all redirected stderr/stdout events have been dispatched
232+
// before disposing. Only the no-arg WaitForExit() guarantees this;
233+
// WaitForExit(int) (used by KillTree) does not.
234+
process.WaitForExit();
237235
}
238236
finally
239237
{

0 commit comments

Comments
 (0)