From 7371713769c583878a29852586627c1bf169cea6 Mon Sep 17 00:00:00 2001 From: Justin Anderson Date: Tue, 15 Jun 2021 08:30:52 -0700 Subject: [PATCH] Handle exception when runtime instance shuts down while enumerating processes. --- .../ClientEndpointInfoSource.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Microsoft.Diagnostics.Monitoring/ClientEndpointInfoSource.cs b/src/Microsoft.Diagnostics.Monitoring/ClientEndpointInfoSource.cs index 7cac048cb3..1a6788a274 100644 --- a/src/Microsoft.Diagnostics.Monitoring/ClientEndpointInfoSource.cs +++ b/src/Microsoft.Diagnostics.Monitoring/ClientEndpointInfoSource.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -26,6 +27,11 @@ public async Task> GetEndpointInfoAsync(CancellationT { return EndpointInfo.FromProcessId(pid); } + // Catch when runtime instance shuts down while attepting to use the established diagnostic port connection. + catch (EndOfStreamException) + { + return null; + } //Catch when the application is running a more privilaged socket than dotnet-monitor. For example, running a web app as administrator //while running dotnet-monitor without elevation. catch (UnauthorizedAccessException)