Skip to content

Commit

Permalink
Fix a timeout exception causing unhandled exception crash (#492) (#494)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
sywhang authored Sep 21, 2019
1 parent 6f638bf commit df35aae
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/Tools/dotnet-counters/CounterMonitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,18 @@ private void StopMonitor()
// 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<int> Monitor(CancellationToken ct, List<string> counter_list, IConsole console, int processId, int refreshInterval)
Expand Down

0 comments on commit df35aae

Please sign in to comment.