Skip to content

Commit

Permalink
fix: Race condition in SentryMessageHandler (#3477)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: James Crosswell <jamescrosswell@users.noreply.github.com>
  • Loading branch information
bitsandfoxes and jamescrosswell authored Jul 12, 2024
1 parent e349e35 commit 5152a3c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## Unreleased

### Fixes
- Race condition in `SentryMessageHandler` ([#3477](https://github.com/getsentry/sentry-dotnet/pull/3477))

## 4.9.0

### Fixes
Expand Down
9 changes: 8 additions & 1 deletion src/Sentry/SentryMessageHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public abstract class SentryMessageHandler : DelegatingHandler
{
private readonly IHub _hub;
private readonly SentryOptions? _options;
private readonly object _innerHandlerLock = new();

/// <summary>
/// Constructs an instance of <see cref="SentryMessageHandler"/>.
Expand Down Expand Up @@ -124,7 +125,13 @@ private void PropagateTraceHeaders(HttpRequestMessage request, string url)
{
// Assign a default inner handler for convenience the first time this is used.
// We can't do this in a constructor, or it will throw when used with HttpMessageHandlerBuilderFilter.
InnerHandler ??= new HttpClientHandler();
if (InnerHandler is null)
{
lock (_innerHandlerLock)
{
InnerHandler ??= new HttpClientHandler();
}
}

if (_options?.TracePropagationTargets.ContainsMatch(url) is true or null)
{
Expand Down

0 comments on commit 5152a3c

Please sign in to comment.