Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Race condition in SentryMessageHandler #3477

Merged
merged 4 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading