Skip to content

Commit 5152a3c

Browse files
fix: Race condition in SentryMessageHandler (#3477)
--------- Co-authored-by: James Crosswell <[email protected]>
1 parent e349e35 commit 5152a3c

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
### Fixes
6+
- Race condition in `SentryMessageHandler` ([#3477](https://github.com/getsentry/sentry-dotnet/pull/3477))
7+
38
## 4.9.0
49

510
### Fixes

src/Sentry/SentryMessageHandler.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public abstract class SentryMessageHandler : DelegatingHandler
1010
{
1111
private readonly IHub _hub;
1212
private readonly SentryOptions? _options;
13+
private readonly object _innerHandlerLock = new();
1314

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

129136
if (_options?.TracePropagationTargets.ContainsMatch(url) is true or null)
130137
{

0 commit comments

Comments
 (0)