Xamarin document offline caching and `InitCacheFlushTimeout`
Opened this issue · 0 comments
Recently a user on Discord asked why a crash (throw null
) right after SentryXamarin.Init
wasn't captured on a Xamarin app.
The explanation is:
When you load the app for the first time, it inits Sentry and immediately crashes. Sentry, writes that crash data to a file (can't send it to Sentry before the app crashes). So when the app restarts, you Init Sentry again, and Sentry sees the file and tries to send. But since that's now blocking the app from launching, it only waits up to 1 second. If ti can't send it to Sentry before that, it lets the app continue to launch. But right after initing Sentry, it crashes again.
So it worked for me, but it might not work for you depending on the latency you have between the device and Sentry for example.
One way around this, is to configure how long you're OK with the SDK blocking the app lunch if it finds a crash file:
SentryXamarin.Init(options =>
{
options.Dsn = "...";
options.InitCacheFlushTimeout = TimeSpan.FromSeconds(10);
});
it will wait "up to 10 seconds" for a crash to be sent when the app restarts. The default is 1 second only I believe
You can also turn it off and if the app is just crashing right while opening up, it will just never capture that
Turns out this is actually documented here: https://docs.sentry.io/platforms/dotnet/configuration/options/#init-cache-flush-timeout
It could be beneficial for Xamarin particularly to get more information about this, since offline caching is on
by default.