Repository navigation
Description
Package
Sentry.AspNetCore
.NET Flavor
.NET
.NET Version
10.0.302 (repro below). Seen in production on .NET 8 (Linux containers).
OS
Any (not platform specific)
OS Version
macOS 26.6 (repro), Linux (production)
Development Environment
Other
Other Error Monitoring Solution
No
SDK Version
7.0.0 (also applies to 6.8.0+, and main at 2e15186)
Self-Hosted Sentry Version
No response
Workload Versions
maui 10.0.20 is installed; the repro doesn't use it.
UseSentry or SentrySdk.Init call
builder.WebHost.UseSentry(o =>
{
o.Dsn = "...";
o.CaptureBlockingCalls = false; // the default
});Steps to Reproduce
Since #5381 (6.8.0), UseSentry() registers the blocking detector as DI singletons for every app, whether or not CaptureBlockingCalls is enabled (SentryWebHostBuilderExtensions.cs#L113-L114):
.AddSingleton<IBlockingMonitor, BlockingMonitor>()
.AddSingleton<TaskBlockingListener>()SentryMiddleware only resolves TaskBlockingListener when CaptureBlockingCalls is true. But TaskBlockingListener is an EventListener, so constructing it is enough to switch on the TPL event source for the whole process, and it never checks the option. Anything else that resolves it turns blocking detection on.
Some frameworks do that on purpose. Cortside.AspNetCore's AddApiDefaults adds a WarmupServicesStartupTask that calls GetServices for every registered singleton type at startup. After upgrading to Sentry 7.0.0, a service using it started sending "Blocking call detected" events at about 20 per minute, with CaptureBlockingCalls false. The events had mechanism BlockingCallDetector and source EventListener, and came from background services (AMQP and Redis connects), so they had no request or transaction.
Minimal repro (Sentry.AspNetCore 7.0.0, Microsoft.NET.Sdk.Web, net10.0):
var blockingEvents = 0;
var builder = WebApplication.CreateBuilder(args);
builder.WebHost.UseSentry(o =>
{
o.Dsn = "https://key@127.0.0.1:9/1"; // unreachable; events are counted in BeforeSend
o.CaptureBlockingCalls = false; // the default, set explicitly
o.SetBeforeSend(e =>
{
if (e.SentryExceptions?.Any(x => x.Mechanism?.Type == "BlockingCallDetector") == true)
Interlocked.Increment(ref blockingEvents);
return null;
});
});
builder.Services.AddHostedService<Blocker>();
var app = builder.Build();
if (args.Contains("--warmup"))
{
// What a "warm up all singletons" startup task does (e.g. Cortside.AspNetCore's WarmupServicesStartupTask).
foreach (var type in builder.Services
.Where(d => d.Lifetime == ServiceLifetime.Singleton && !d.ServiceType.ContainsGenericParameters)
.Select(d => d.ServiceType).Distinct())
{
try { _ = app.Services.GetServices(type).ToList(); } catch { }
}
}
await app.StartAsync();
await Task.Delay(5000);
Console.WriteLine($"warmup={args.Contains("--warmup")} blockingEvents={blockingEvents}");
await app.StopAsync();
class Blocker : BackgroundService
{
protected override async Task ExecuteAsync(CancellationToken ct)
{
while (!ct.IsCancellationRequested)
{
await Task.Run(() => Task.Delay(20).Wait(), ct); // sync-over-async on a thread-pool thread
await Task.Delay(500, ct);
}
}
}dotnet rundotnet run -- --warmup
Expected Result
With CaptureBlockingCalls = false, no blocking-call events in either run, and the TPL event source stays off.
Actual Result
warmup=False blockingEvents=0
warmup=True blockingEvents=10
With the warm-up, the listener gets constructed and every sync-over-async wait on a thread-pool thread is reported, even though the option is off. In our case that rate would have burned through the monthly error quota in under two days. The process also runs a Verbose TPL listener that nobody enabled.
Possible fixes:
- Register the listener (and monitor) with a factory that only builds them when
CaptureBlockingCallsis true, e.g.AddSingleton(sp => sp.GetRequiredService<IOptions<SentryAspNetCoreOptions>>().Value.CaptureBlockingCalls ? new TaskBlockingListener(...) : null!), or only register them when the option is on. - Or have
TaskBlockingListenernot enable the TPL source until something opts in, so constructing it has no side effect.
Workaround we're using: after UseSentry(...), replace the TaskBlockingListener service descriptor with a factory that returns null unless CaptureBlockingCalls is true. That relies on an internal type, so a fix in the SDK would be much better.
Metadata
Metadata
Assignees
Projects
- StatusShow more project fieldsNo status
Activity
linear-code commentedon Nov 19, 2026
NET-943
jamescrosswell commentedon Nov 19, 2026
Thanks for the report @JehutyPT - preparing a fix now:
jamescrosswell commentedon Nov 19, 2026
Thanks for the detailed report and the repro, they made this easy to pin down.
Fixed in #5970, which will ship in the next release.
TaskBlockingListenerno longer enables the TPL event source when it's constructed. OnlySentryMiddlewareturns it on, and only whenCaptureBlockingCallsis true, so resolving it from the container (e.g. a warm-up task) has no side effect. Once you've upgraded you can drop the descriptor-replacement workaround.fix(aspnetcore): blocking-call detection no longer runs when CaptureB…