WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit df35aae

Browse files
authored
Fix a timeout exception causing unhandled exception crash (#492) (#494)
* 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
1 parent 6f638bf commit df35aae

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/Tools/dotnet-counters/CounterMonitor.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,18 @@ private void StopMonitor()
7676
// If the app we're monitoring exits abruptly, this may throw in which case we just swallow the exception and exit gracefully.
7777
Debug.WriteLine($"[ERROR] {ex.ToString()}");
7878
}
79+
// We may time out if the process ended before we sent StopTracing command. We can just exit in that case.
80+
catch (TimeoutException)
81+
{
82+
}
83+
// On Unix platforms, we may actually get a PNSE since the pipe is gone with the process, and Runtime Client Library
84+
// does not know how to distinguish a situation where there is no pipe to begin with, or where the process has exited
85+
// before dotnet-counters and got rid of a pipe that once existed.
86+
// Since we are catching this in StopMonitor() we know that the pipe once existed (otherwise the exception would've
87+
// been thrown in StartMonitor directly)
88+
catch (PlatformNotSupportedException)
89+
{
90+
}
7991
}
8092

8193
public async Task<int> Monitor(CancellationToken ct, List<string> counter_list, IConsole console, int processId, int refreshInterval)

0 commit comments

Comments
 (0)