From: Sung Yoon Whang Date: Sat, 21 Sep 2019 00:14:41 +0000 (-0700) Subject: Fix a timeout exception causing unhandled exception crash (#492) X-Git-Tag: submit/tizen/20200402.013218~14^2^2~48 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ec26ac10bf46247409977d1dd7838691a4b42e03;p=platform%2Fcore%2Fdotnet%2Fdiagnostics.git Fix a timeout exception causing unhandled exception crash (#492) * Fix a timeout exception causing unhandled exception crash * Fix the same issue on Unix too * Move the exception handling to StopMonitor to distinguish actually incompatible runtimes from early exits * fix build error --- diff --git a/src/Tools/dotnet-counters/CounterMonitor.cs b/src/Tools/dotnet-counters/CounterMonitor.cs index 3649444b2..d7cf5ebba 100644 --- a/src/Tools/dotnet-counters/CounterMonitor.cs +++ b/src/Tools/dotnet-counters/CounterMonitor.cs @@ -76,6 +76,18 @@ namespace Microsoft.Diagnostics.Tools.Counters // If the app we're monitoring exits abruptly, this may throw in which case we just swallow the exception and exit gracefully. Debug.WriteLine($"[ERROR] {ex.ToString()}"); } + // We may time out if the process ended before we sent StopTracing command. We can just exit in that case. + catch (TimeoutException) + { + } + // On Unix platforms, we may actually get a PNSE since the pipe is gone with the process, and Runtime Client Library + // does not know how to distinguish a situation where there is no pipe to begin with, or where the process has exited + // before dotnet-counters and got rid of a pipe that once existed. + // Since we are catching this in StopMonitor() we know that the pipe once existed (otherwise the exception would've + // been thrown in StartMonitor directly) + catch (PlatformNotSupportedException) + { + } } public async Task Monitor(CancellationToken ct, List counter_list, IConsole console, int processId, int refreshInterval)