Skip to content

Commit

Permalink
Merge pull request #534 from MindscapeHQ/sean/fix-potential-ui-deadlocks
Browse files Browse the repository at this point in the history
Add `ConfigureAwait(false)` to the blocking and non blocking Send calls
  • Loading branch information
xenolightning authored Jun 14, 2024
2 parents 2da34c2 + 6c74596 commit 51acb69
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGE-LOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Full Change Log for Raygun4Net.* packages

### v11.0.1
- Raygun4Net.NetCore
- Deprecated `RaygunClientBase.Send()`. The asynchronous `SendAsync()` should be preferred in all scenarios to avoid potential deadlocks
- Improve the potential deadlocks when calling `Send()` from a UI Thread by adding `ConfigureAwait(false)`
- Note: This does not entirely remove the possibility of deadlocks, and `Send()` should not be used within a UI context

### v11.0.0
- Add support for PDB Debug Information in stack traces
- This enables Raygun to leverage Portable PDBs to symbolicate .NET stack traces when PDBs are not included in the build output
Expand Down
25 changes: 19 additions & 6 deletions Mindscape.Raygun4Net.NetCore.Common/RaygunClientBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ protected virtual bool CanSend(RaygunMessage message)
/// Transmits an exception to Raygun synchronously.
/// </summary>
/// <param name="exception">The exception to deliver.</param>
[Obsolete("Please use SendAsync() to avoid possible deadlocks")]
public void Send(Exception exception)
{
Send(exception, null, null);
Expand All @@ -300,6 +301,7 @@ public void Send(Exception exception)
/// </summary>
/// <param name="exception">The exception to deliver.</param>
/// <param name="tags">A list of strings associated with the message.</param>
[Obsolete("Please use SendAsync() to avoid possible deadlocks")]
public void Send(Exception exception, IList<string> tags)
{
Send(exception, tags, null);
Expand All @@ -312,11 +314,12 @@ public void Send(Exception exception, IList<string> tags)
/// <param name="exception">The exception to deliver.</param>
/// <param name="tags">A list of strings associated with the message.</param>
/// <param name="userCustomData">A key-value collection of custom data that will be added to the payload.</param>
[Obsolete("Please use SendAsync() to avoid possible deadlocks")]
public void Send(Exception exception, IList<string> tags, IDictionary userCustomData)
{
try
{
SendAsync(exception, tags, userCustomData).GetAwaiter().GetResult();
SendAsync(exception, tags, userCustomData).ConfigureAwait(false).GetAwaiter().GetResult();
}
catch
{
Expand All @@ -332,9 +335,19 @@ public void Send(Exception exception, IList<string> tags, IDictionary userCustom
/// Transmits an exception to Raygun asynchronously.
/// </summary>
/// <param name="exception">The exception to deliver.</param>
public Task SendAsync(Exception exception)
public async Task SendAsync(Exception exception)
{
return SendAsync(exception, null, null);
await SendAsync(exception, null, null).ConfigureAwait(false);
}

/// <summary>
/// Transmits an exception to Raygun asynchronously.
/// </summary>
/// <param name="exception">The exception to deliver.</param>
/// <param name="tags">A list of strings associated with the message.</param>
public async Task SendAsync(Exception exception, IList<string> tags)
{
await SendAsync(exception, tags, null).ConfigureAwait(false);
}

/// <summary>
Expand Down Expand Up @@ -505,7 +518,7 @@ public async Task Send(RaygunMessage raygunMessage, CancellationToken cancellati
try
{
var messagePayload = SimpleJson.SerializeObject(raygunMessage);
await SendPayloadAsync(messagePayload, _settings.ApiKey, true, cancellationToken);
await SendPayloadAsync(messagePayload, _settings.ApiKey, true, cancellationToken).ConfigureAwait(false);
}
catch (Exception ex)
{
Expand All @@ -518,7 +531,7 @@ public async Task Send(RaygunMessage raygunMessage, CancellationToken cancellati

private async Task SendOfflinePayloadAsync(string payload, string apiKey, CancellationToken cancellationToken)
{
await SendPayloadAsync(payload, apiKey, false, cancellationToken);
await SendPayloadAsync(payload, apiKey, false, cancellationToken).ConfigureAwait(false);
}

private async Task SendPayloadAsync(string payload, string apiKey, bool useOfflineStore, CancellationToken cancellationToken)
Expand Down Expand Up @@ -561,7 +574,7 @@ private async Task<bool> SaveMessageToOfflineCache(string messagePayload, string
return false;
}

return await _settings.OfflineStore.Save(messagePayload, apiKey, cancellationToken);
return await _settings.OfflineStore.Save(messagePayload, apiKey, cancellationToken).ConfigureAwait(false);
}
}
}

0 comments on commit 51acb69

Please sign in to comment.