Skip to content

Commit 26964af

Browse files
committed
Fix race
1 parent 59fd67a commit 26964af

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/Platform/Microsoft.Testing.Platform/Hosts/CommonTestHost.cs

+5-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,11 @@ public async Task<int> RunAsync()
6969
await DisposeServiceProviderAsync(ServiceProvider, isProcessShutdown: true);
7070
await DisposeHelper.DisposeAsync(ServiceProvider.GetService<FileLoggerProvider>());
7171
await DisposeHelper.DisposeAsync(PushOnlyProtocol);
72-
await DisposeHelper.DisposeAsync(ServiceProvider.GetTestApplicationCancellationTokenSource());
72+
73+
// This is intentional that we are not disposing the CTS.
74+
// An unobserved task exception could be raised after the dispose, and we want to use OutputDevice there
75+
// which needs CTS down the path.
76+
// await DisposeHelper.DisposeAsync(ServiceProvider.GetTestApplicationCancellationTokenSource());
7377
}
7478

7579
if (testApplicationCancellationToken.IsCancellationRequested)

src/Platform/Microsoft.Testing.Platform/Hosts/ServerTestHost.cs

+5
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,11 @@ public void Dispose()
660660
{
661661
// Note: The lifetime of the _reader/_writer should be currently handled by the RunAsync()
662662
// We could consider creating a stateful engine that has the lifetime == server connection UP.
663+
if (!ServiceProvider.GetUnhandledExceptionsPolicy().FastFailOnFailure)
664+
{
665+
AppDomain.CurrentDomain.UnhandledException -= OnCurrentDomainUnhandledException;
666+
TaskScheduler.UnobservedTaskException -= OnTaskSchedulerUnobservedTaskException;
667+
}
663668
}
664669

665670
internal async Task SendTestUpdateCompleteAsync(Guid runId)

0 commit comments

Comments
 (0)