Skip to content
This repository has been archived by the owner on Jul 5, 2020. It is now read-only.

Commit

Permalink
LiveMetrics background thread safeguards added to never throw unhandl…
Browse files Browse the repository at this point in the history
…ed exception (#1246)

* LiveMetrics background thread safeguards added to never throw unhandled exception.
  • Loading branch information
cijothomas authored Jul 25, 2019
1 parent a43692c commit 0eb4ae2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Version 2.11.0-beta2
- [Add NetStandard2.0 Target for WindowsServerPackage](https://github.com/Microsoft/ApplicationInsights-dotnet-server/issues/1212)
- [Add NetStandard2.0 Target for DependencyCollector](https://github.com/Microsoft/ApplicationInsights-dotnet-server/issues/1212)
- [QuickPulse/LiveMetrics background thread safeguards added to never throw unhandled exception.](https://github.com/microsoft/ApplicationInsights-dotnet-server/issues/1088)

## Version 2.11.0-beta1
- [Add support for Event Counter collection.](https://github.com/Microsoft/ApplicationInsights-dotnet-server/issues/1222)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{
using System;
using System.Threading;
using Microsoft.ApplicationInsights.Extensibility.Implementation.Tracing;

internal class QuickPulseThreadModuleScheduler : IQuickPulseModuleScheduler
{
Expand Down Expand Up @@ -47,7 +48,23 @@ public void Dispose()

private void Worker(object state)
{
(state as Action<CancellationToken>)?.Invoke(this.cancellationTokenSource.Token);
try
{
(state as Action<CancellationToken>)?.Invoke(this.cancellationTokenSource.Token);
}
catch (Exception ex)
{
// This is a Thread, and we don't want any exception thrown ever from this part as this would cause application crash.
try
{
QuickPulseEventSource.Log.UnknownErrorEvent(ex.ToInvariantString());
}
catch (Exception)
{
// Intentionally empty. If EventSource writing itself is failing as well, there is nothing more to be done here.
// The best that can be done is atleast prevent application crash due to unhandledexception from Thread.
}
}
}
}
}
Expand Down

0 comments on commit 0eb4ae2

Please sign in to comment.