When Caching is enabled, flushing (e.g. on Dispose) sometimes does not flush all events on app crash
See original GitHub issuePackage
Sentry
.NET Flavor
.NET
.NET Version
6.0.1
OS
Any (not platform specific)
SDK Version
3.22.0
Steps to Reproduce
- Initialize sentry SDK and set
CacheDirectoryPath
- Capture event
- Invoke sentrySdk’s
Dispose
from other thread and wait it to complete - Exit app
Attached source code using which it’s reproducible on MacOS ( I am using Macbook Air 2020 M1 with OS BigSur 11.5.1 )
public static class Program
{
static void Main()
{
var sentryDisposableClient = SentrySdk.Init(sentryOptions =>
{
sentryOptions.Dsn = // path to dsn
sentryOptions.Release = "0.0.0.1";
sentryOptions.Environment = "Debug";
sentryOptions.CacheDirectoryPath = AppDomain.CurrentDomain.BaseDirectory;
sentryOptions.IsGlobalModeEnabled = true;
sentryOptions.ShutdownTimeout = TimeSpan.FromSeconds(10);
sentryOptions.InitCacheFlushTimeout = TimeSpan.Zero;
sentryOptions.StackTraceMode = StackTraceMode.Original;
sentryOptions.DisableAppDomainProcessExitFlush();
sentryOptions.DisableAppDomainUnhandledExceptionCapture();
sentryOptions.AutoSessionTracking = true;
});
var capturedEventId = SentrySdk.CaptureEvent(
new SentryEvent(new System.Exception("description to easily find this particular exception"))
{
Level = SentryLevel.Fatal
});
InvokeAsBackgroundTask(sentryDisposableClient.Dispose)
.Wait(TimeSpan.FromSeconds(10));
Console.WriteLine($"Failing fast after capturing {capturedEventId}");
Environment.FailFast("1");
}
static Task InvokeAsBackgroundTask(Action action)
{
var taskCompletionSource = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
var backgroundThread = new Thread(() =>
{
try
{
action.Invoke();
taskCompletionSource.TrySetResult();
}
catch (Exception ex)
{
taskCompletionSource.TrySetException(ex);
}
});
backgroundThread.IsBackground = true;
backgroundThread.Start();
return taskCompletionSource.Task;
}
}
Expected Result
Logs are sent on application crash ( just before the app finishes execution )
Actual Result
Logs are NOT sent on application crash, and .envelope
file is created in %CACHE_DIR%/%dsn.hash%/_processing
soon after app is exited.
Issue Analytics
- State:
- Created a year ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
RedisConnectionException: No connection is available to ...
Running Azure Redis Cache, Client host: Azure VM. Clients and Server are located in the same region. RedisConnectionException: Message: No ...
Read more >How to dispose when application crashes
If your application crashes, there's not much you can do to make sure that the unmanaged resources are disposed.
Read more >Sentry for .net MAUI causes app crash upon startup #2000
[DOTNET] Debug: Successfully flushed all events up to call to FlushAsync. [DOTNET] Debug: Flushing caching transport with remaining flush ...
Read more >ASP.NET Core Best Practices
By Mike Rousos. This article provides guidelines for maximizing performance and reliability of ASP.NET Core apps.
Read more >MemoryCache.Dispose Method (System.Runtime.Caching)
The state of the cache is set to indicate that the cache is disposed. Any attempt to call public caching methods that change...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@mattjohnsonpint Tried with version 3.23.1, issue not reproduced.
Many thanks for prompt reply and addressing the issue.
@v1adis1ave - This issue should be resolved with release 3.23.1. Please update and confirm. Thanks.