Commit 4c6633a
committed
Fix race condition in ExecuteInIsolationAsync causing net472 test host crash
The Process.Exited event fires as soon as the child process terminates, but
OutputDataReceived/ErrorDataReceived callbacks can still fire afterward while
the OS pipe buffers are being drained. Previously, the test awaited only the
process exit, so the test method could return (and xunit could deactivate the
TestOutputHelper) before all output was consumed. Late-arriving output then
called logger.WriteLine() with no active test, causing xunit v3's strict
TestOutputHelper to throw InvalidOperationException on a threadpool thread,
crashing the test host process (exit code 7).
This was exposed by the upgrade from xunit.runner.visualstudio (VSTest) to
xunit.v3.mtp-v2 (MTP v2), which enforces that QueueTestOutput is only called
while a test is active.
Fix: track stdout/stderr EOF via TaskCompletionSources (signaled when
e.Data is null) and wait for both stream completions in addition to the
process exit before returning from the test.1 parent 4a4b69b commit 4c6633a
1 file changed
Lines changed: 43 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
238 | 238 | | |
239 | 239 | | |
240 | 240 | | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
241 | 249 | | |
242 | 250 | | |
243 | | - | |
244 | | - | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
245 | 275 | | |
246 | 276 | | |
247 | 277 | | |
| |||
254 | 284 | | |
255 | 285 | | |
256 | 286 | | |
257 | | - | |
258 | | - | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
259 | 295 | | |
260 | | - | |
| 296 | + | |
| 297 | + | |
261 | 298 | | |
262 | 299 | | |
263 | 300 | | |
264 | 301 | | |
265 | 302 | | |
266 | | - | |
| 303 | + | |
267 | 304 | | |
268 | 305 | | |
269 | 306 | | |
| |||
0 commit comments