Skip to content

Commit 1826e6b

Browse files
Copilotstephentoub
andcommitted
Guard WaitForExit() with HasExited check to avoid hanging if kill times out
If KillTree's kill succeeds but WaitForExit(int) times out, the process is still alive. Calling WaitForExit() (no args) unconditionally would then block indefinitely. Guard with HasExited to only flush stderr events when we know the process has actually exited. Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
1 parent 1a58fd5 commit 1826e6b

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

src/ModelContextProtocol.Core/Client/StdioClientTransport.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,12 @@ internal static void DisposeProcess(
230230

231231
// Ensure all redirected stderr/stdout events have been dispatched
232232
// before disposing. Only the no-arg WaitForExit() guarantees this;
233-
// WaitForExit(int) (used by KillTree) does not.
234-
process.WaitForExit();
233+
// WaitForExit(int) (used by KillTree) does not. Guard with HasExited
234+
// to avoid hanging indefinitely if the process couldn't be killed.
235+
if (HasExited(process))
236+
{
237+
process.WaitForExit();
238+
}
235239
}
236240
finally
237241
{

0 commit comments

Comments
 (0)