Commit 7ff9d2f
Fix stderr drain cancelled prematurely by CancelShutdown race
GetUnexpectedExitExceptionAsync used a linked CancellationTokenSource
that included the caller's token (_shutdownCts.Token). When
ReadMessagesAsync and DisposeAsync race to call CleanupAsync, the
loser calls CancelShutdown() which cancels _shutdownCts. This
prematurely aborted WaitForExitAsync in the winner's cleanup path,
preventing stderr pipe buffers from being fully drained. The
ErrorDataReceived callback would never fire for lines still in the
pipe, causing CreateAsync_ValidProcessInvalidServer_StdErrCallbackInvoked
to fail intermittently.
Fix: use a standalone timeout CTS instead of linking to the caller's
token. The process is already dead at this point—we only need a
timeout to bound the pipe drain, not external cancellation.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent 0665aaf commit 7ff9d2f
File tree
1 file changed
+7
-8
lines changed- src/ModelContextProtocol.Core/Client
1 file changed
+7
-8
lines changedLines changed: 7 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | | - | |
| 38 | + | |
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| |||
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
62 | | - | |
| 62 | + | |
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
| |||
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
91 | | - | |
| 91 | + | |
92 | 92 | | |
93 | 93 | | |
94 | 94 | | |
| |||
100 | 100 | | |
101 | 101 | | |
102 | 102 | | |
103 | | - | |
104 | | - | |
105 | | - | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
106 | 106 | | |
107 | | - | |
108 | | - | |
| 107 | + | |
109 | 108 | | |
110 | 109 | | |
111 | 110 | | |
| |||
0 commit comments