question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

When Caching is enabled, flushing (e.g. on Dispose) sometimes does not flush all events on app crash

See original GitHub issue

Package

Sentry

.NET Flavor

.NET

.NET Version

6.0.1

OS

Any (not platform specific)

SDK Version

3.22.0

Steps to Reproduce

  1. Initialize sentry SDK and set CacheDirectoryPath
  2. Capture event
  3. Invoke sentrySdk’s Dispose from other thread and wait it to complete
  4. 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:closed
  • Created a year ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
v1adis1avecommented, Nov 11, 2022

@mattjohnsonpint Tried with version 3.23.1, issue not reproduced.

Many thanks for prompt reply and addressing the issue.

0reactions
mattjohnsonpintcommented, Oct 31, 2022

@v1adis1ave - This issue should be resolved with release 3.23.1. Please update and confirm. Thanks.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found