Skip to content

Commit

Permalink
Merge pull request #362 from MindscapeHQ/fix-net4-sendinbackground-no…
Browse files Browse the repository at this point in the history
…t-swalling-all-errors

Wrap whole SendInBackground method in try/catch to prevent errors cau…
  • Loading branch information
UberMouse authored Oct 12, 2017
2 parents 76962ca + 963170b commit 0f232cd
Showing 1 changed file with 40 additions and 27 deletions.
67 changes: 40 additions & 27 deletions Mindscape.Raygun4Net4/RaygunClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -315,36 +315,49 @@ public void SendInBackground(Exception exception, IList<string> tags, IDictionar
/// <param name="userInfo">Information about the user including the identity string.</param>
public void SendInBackground(Exception exception, IList<string> tags, IDictionary userCustomData, RaygunIdentifierMessage userInfo)
{
if (CanSend(exception))
try
{
// We need to process the HttpRequestMessage on the current thread,
// otherwise it will be disposed while we are using it on the other thread.
RaygunRequestMessage currentRequestMessage = BuildRequestMessage();
// We need to retrieve the breadcrumbs on the current thread as the HttpContext.Current
// will be null on the other thread
var currentBreadcrumbs = _breadcrumbs.ToList();
var currentTime = DateTime.UtcNow;

ThreadPool.QueueUserWorkItem(c =>
if (CanSend(exception))
{
try
{
_currentRequestMessage = currentRequestMessage;
_currentBreadcrumbs = currentBreadcrumbs;

StripAndSend(exception, tags, userCustomData, userInfo, currentTime);
}
catch (Exception)
{
// This will swallow any unhandled exceptions unless we explicitly want to throw on error.
// Otherwise this can bring the whole process down.
if (RaygunSettings.Settings.ThrowOnError)
// We need to process the HttpRequestMessage on the current thread,
// otherwise it will be disposed while we are using it on the other thread.
RaygunRequestMessage currentRequestMessage = BuildRequestMessage();
// We need to retrieve the breadcrumbs on the current thread as the HttpContext.Current
// will be null on the other thread
var currentBreadcrumbs = _breadcrumbs.ToList();
var currentTime = DateTime.UtcNow;

ThreadPool.QueueUserWorkItem(
c =>
{
throw;
}
}
});
FlagAsSent(exception);
try
{
_currentRequestMessage = currentRequestMessage;
_currentBreadcrumbs = currentBreadcrumbs;

StripAndSend(exception, tags, userCustomData, userInfo, currentTime);
}
catch (Exception)
{
// This will swallow any unhandled exceptions unless we explicitly want to throw on error.
// Otherwise this can bring the whole process down.
if (RaygunSettings.Settings.ThrowOnError)
{
throw;
}
}
});
FlagAsSent(exception);
}
}
catch (Exception)
{
// This will swallow any unhandled exceptions unless we explicitly want to throw on error.
// Otherwise this can bring the whole process down.
if (RaygunSettings.Settings.ThrowOnError)
{
throw;
}
}
}

Expand Down

0 comments on commit 0f232cd

Please sign in to comment.