Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disposing the Hub with AutoSessionTracking gives an error #1374

Closed
lucas-zimerman opened this issue Dec 8, 2021 · 6 comments
Closed

Disposing the Hub with AutoSessionTracking gives an error #1374

lucas-zimerman opened this issue Dec 8, 2021 · 6 comments
Labels
Bug Something isn't working Offline Caching

Comments

@lucas-zimerman
Copy link
Collaborator

As observed on Unity, when you dispose of a hub and usingAutoSessionTracking, an error will be thrown once the SDK disposes of the SDK hub. You can reproduce the error with the following snippet:

void StartSentry()
{
    SentrySdk.Init(o =>
    {
        o.Dsn = "https://eb18e953812b41c3aeb042e666fd3b5c@o447951.ingest.sentry.io/5428537";
        o.AutoSessionTracking = true;
        o.CacheDirectoryPath = "C:/Users/.../AppData/LocalLow/Sentry/Sentry Defenses/Sentry";
        o.Debug = true;
    });
}
StartSentry();
StartSentry();
Console.ReadKey();

The following error was received:

Error: Failed to send cached envelope: C:/Users/lucas/AppData/LocalLow/Sentry/Sentry Defenses/Sentry\Sentry\132A73C90BBA506000857BC4BFC23E574F1551B5\__processing\1638992610_1647__6590935.envelope, retrying after a delay.
System.Threading.Tasks.TaskCanceledException: A task was canceled.
   at Sentry.Internal.Extensions.StreamExtensions.ReadAllBytesAsync(Stream stream, CancellationToken cancellationToken)+MoveNext() in D:\Development\Online Projects\Sentry\sentry-dotnet\src\Sentry\Internal\Extensions\StreamExtensions.cs:line 18
   at Sentry.Internal.Extensions.StreamExtensions.ReadAllBytesAsync(Stream stream, CancellationToken cancellationToken)+System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult()
   at Sentry.Protocol.Envelopes.Envelope.DeserializeHeaderAsync(Stream stream, CancellationToken cancellationToken) in D:\Development\Online Projects\Sentry\sentry-dotnet\src\Sentry\Envelopes\Envelope.cs:line 188
   at Sentry.Protocol.Envelopes.Envelope.DeserializeHeaderAsync(Stream stream, CancellationToken cancellationToken) in D:\Development\Online Projects\Sentry\sentry-dotnet\src\Sentry\Envelopes\Envelope.cs:line 188
   at Sentry.Protocol.Envelopes.Envelope.DeserializeAsync(Stream stream, CancellationToken cancellationToken) in D:\Development\Online Projects\Sentry\sentry-dotnet\src\Sentry\Envelopes\Envelope.cs:line 212
   at Sentry.Internal.Http.CachingTransport.InnerProcessCacheAsync(String envelopeFilePath, CancellationToken cancellationToken) in D:\Development\Online Projects\Sentry\sentry-dotnet\src\Sentry\Internal\Http\CachingTransport.cs:line 195
   at Sentry.Internal.Http.CachingTransport.InnerProcessCacheAsync(String envelopeFilePath, CancellationToken cancellationToken) in D:\Development\Online Projects\Sentry\sentry-dotnet\src\Sentry\Internal\Http\CachingTransport.cs:line 207
   at Sentry.Internal.Http.CachingTransport.ProcessCacheAsync(CancellationToken cancellationToken) in D:\Development\Online Projects\Sentry\sentry-dotnet\src\Sentry\Internal\Http\CachingTransport.cs:line 159  Debug: Background worker of CachingTransport has shutdown.
@lucas-zimerman lucas-zimerman added Bug Something isn't working Offline Caching labels Dec 8, 2021
@bruno-garcia
Copy link
Member

The SDK is getting Disposed when Init is called again. So the behavior is correct there.
The issue is: Why is it getting Inititalized twice? Init is supposed to be called once in the app lifecycle

@SimonCropp
Copy link
Contributor

Init is supposed to be called once in the app lifecycle

so should we throw on the second init call?

@SimonCropp
Copy link
Contributor

@bruno-garcia @lucas-zimerman thoughts on the above?

@vaind
Copy link
Collaborator

vaind commented Jul 11, 2022

so should we throw on the second init call?

That would be breaking though, wouldn't it?

@bruno-garcia
Copy link
Member

bruno-garcia commented Jul 11, 2022

The SDK should be OK with being disposed without breaking internally though. Once there's "more information" a following Init call is done. That's not ideal but can happen, also when there are more than 1 package and "init" is setup on both. That's not ideal but because it's a bit of a trap that each integration can initialize, it can happen. The static SentrySdk class does an atomic swap between hubs (old to new) so we can flush it and let it go out of scope so GC does it's thing. Since we don't want to Dispose in favor to Flushing only (see #599 ), it's possible finalizer thread will need to clear some unmanaged resources if we happened to allocate one in the previous calls

@mattjohnsonpint
Copy link
Contributor

Closing in favor of #2033

@mattjohnsonpint mattjohnsonpint closed this as not planned Won't fix, can't repro, duplicate, stale Feb 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Offline Caching
Projects
Archived in project
Development

No branches or pull requests

6 participants