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

[Xamarin] [iOS & Android] Random Internal Crash in Sentry.Internal.Extensions.StreamExtensions+<ReadAllBytesAsync> #1963

Closed
khalilyamoun opened this issue Oct 5, 2022 · 5 comments · Fixed by #1965
Assignees
Labels
Bug Something isn't working

Comments

@khalilyamoun
Copy link

khalilyamoun commented Oct 5, 2022

Package

Sentry

.NET Flavor

Xamarin

.NET Version

6.0.401

OS

Any (not platform specific)

SDK Version

Sentry Xamarin 1.4.2 / Sentry.NET SDK 3.20.1

Self-Hosted Sentry Version

No response

Steps to Reproduce

Unfortunately, we didn't find any repro to the issue.
By seeing the Logs, the app crashes randomly.
On our app, we send many events (for basically every click / navigation)

Expected Result

The app should not crash.

Actual Result

System.InvalidOperationException: Operation is not valid due to the current state of the object.
  at System.Threading.Tasks.Sources.ManualResetValueTaskSourceCoreShared.CompletionSentinel (System.Object _) [0x00000] in <0e338e4ca0054dd19c56e9a51aa6e2f3>:0
  at System.Threading.Tasks.Sources.ManualResetValueTaskSourceCore`1[TResult].InvokeContinuation () [0x0005a] in <0e338e4ca0054dd19c56e9a51aa6e2f3>:0
  at System.Threading.Tasks.Sources.ManualResetValueTaskSourceCore`1[TResult].SignalCompletion () [0x00063] in <0e338e4ca0054dd19c56e9a51aa6e2f3>:0
  at System.Threading.Tasks.Sources.ManualResetValueTaskSourceCore`1[TResult].SetResult (TResult result) [0x00007] in <0e338e4ca0054dd19c56e9a51aa6e2f3>:0

  at Sentry.Internal.Extensions.StreamExtensions+<ReadAllBytesAsync>d__0.MoveNext () [0x001b9] in <c6891296f43443389af454d6ade2ce97>:0

  at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.InvokeMoveNext (System.Object stateMachine) [0x00000] in <0e338e4ca0054dd19c56e9a51aa6e2f3>:0
  at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00071] in <0e338e4ca0054dd19c56e9a51aa6e2f3>:0
  at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <0e338e4ca0054dd19c56e9a51aa6e2f3>:0
  at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run () [0x00024] in <0e338e4ca0054dd19c56e9a51aa6e2f3>:0
  at System.Threading.Tasks.AwaitTaskContinuation.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem () [0x00008] in <0e338e4ca0054dd19c56e9a51aa6e2f3>:0
  at System.Threading.ThreadPoolWorkQueue.Dispatch () [0x00074] in <0e338e4ca0054dd19c56e9a51aa6e2f3>:0
  at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback () [0x00000] in <0e338e4ca0054dd19c56e9a51aa6e2f3>:0
@khalilyamoun khalilyamoun added Bug Something isn't working Platform: .NET labels Oct 5, 2022
@bruno-garcia bruno-garcia moved this to Needs Discussion in Mobile & Cross Platform SDK Oct 5, 2022
@mattjohnsonpint mattjohnsonpint self-assigned this Oct 5, 2022
@mattjohnsonpint mattjohnsonpint moved this from Needs Discussion to Needs Investigation in Mobile & Cross Platform SDK Oct 5, 2022
@mattjohnsonpint
Copy link
Contributor

Thanks for reporting this!

It would appear to be happening when our caching transport is deserializing items from the cache. Thus if you disable caching, the problem would go away - but of course, so would the benefits of caching (such as collecting events when the user is offline for later sending, etc.). If you want to do that as a temporary workaround, for Sentry.Xamarin you can call o.DisableOfflineCaching() in your initialization.

The only clue I have about the actual issue from the stack trace given is that while enumerating the IAsyncEnumerable, it somehow reaches this code, which apparently is supposed to never be invoked. If we could get a consistent reproduction, then I would report that upstream to https://github.com/dotnet/runtime.

That said, I think I can refactor this code to avoid IAsyncEnumerable completely. In particular, we're streaming one byte at a time, so we're not making the best use of buffers. I'll fix that for the next release. There's a few other things nearby to improve also.

@mattjohnsonpint mattjohnsonpint moved this from Needs Investigation to In Progress in Mobile & Cross Platform SDK Oct 5, 2022
Repository owner moved this from In Progress to Done in Mobile & Cross Platform SDK Oct 6, 2022
@khalilyamoun
Copy link
Author

khalilyamoun commented Oct 6, 2022

Thanks @mattjohnsonpint for your response and for the fix/enhancement 😊
Do you have any idea when the next release (the one that has the fix) will be published?

@mattjohnsonpint
Copy link
Contributor

@khalilyamoun - It's out now. Try 3.22.0 and please let us know if it fixes the issue or not.

Thanks!

@khalilyamoun
Copy link
Author

Thanks @mattjohnsonpint,
Can we have a new Sentry Xamarin release also ? (that bumps Sentry.NET SDK to 3.22.0) ?

@mattjohnsonpint
Copy link
Contributor

mattjohnsonpint commented Oct 7, 2022

@khalilyamoun - That will happen soon, but since it's a direct nuget dependency, you can add both Sentry.Xamarin and Sentry to your project to get the latest versions of each.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants