getsentry / sentry-xamarin

Sentry for Xamarin Native and Xamarin.Forms
https://docs.sentry.io/platforms/dotnet/guides/xamarin/
44 stars 11 forks source link

System.AggregateException from Sentry assembly in Xamarin.Droid app #115

Closed caiofbpa closed 2 years ago

caiofbpa commented 2 years ago

Environment

How do you use Sentry? Sentry SaaS (sentry.io)

Which SDK and version? Sentry.Xamarin 1.4.0

Steps to Reproduce

  1. Install Sentry.Xamarin in our Xamarin.Droid app
  2. Serve tens of thousands of users
  3. See random crashes coming out of Sentry.Xamarin itself

Expected Result

No crash should come from Sentry.Xamarin assemblies.

Actual Result

We're seeing this crash being reported in Sentry in our Xamarin.Droid app:

System.AggregateException
A Task's exception(s) were not observed either by Waiting on the Task or accessing its Exception property. As a result, the unobserved exception was rethrown by the finalizer thread. (No such host is known)
System.Net.Sockets.SocketException: No such host is known
  ?, in async ValueTask<ValueTuple<Socket, Stream>> ConnectHelper.ConnectAsync(string host, int port, CancellationToken cancellationToken)
System.Net.Http.HttpRequestException: No such host is known
  ?, in async ValueTask<ValueTuple<Socket, Stream>> ConnectHelper.ConnectAsync(string host, int port, CancellationToken cancellationToken)
  ?, in async ValueTask<ValueTuple<HttpConnection, HttpResponseMessage>> HttpConnectionPool.CreateConnectionAsync(HttpRequestMessage request, CancellationToken cancellationToken)
  ?, in async ValueTask<ValueTuple<HttpConnection, HttpResponseMessage>> HttpConnectionPool.WaitForCreatedConnectionAsync(ValueTask<ValueTuple<HttpConnection, HttpResponseMessage>> creationTask)
  ?, in async Task<HttpResponseMessage> HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, bool doRequestAuth, CancellationToken cancellationToken)
  ?, in async Task<HttpResponseMessage> RedirectHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
  ?, in async Task<HttpResponseMessage> DecompressionHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
  ?, in async Task<HttpResponseMessage> GzipBufferedRequestBodyHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
  ?, in async Task<HttpResponseMessage> RetryAfterHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
  ?, in async Task<HttpResponseMessage> HttpClient.FinishSendAsyncBuffered(Task<HttpResponseMessage> sendTask, HttpRequestMessage request, CancellationTokenSource cts, bool disposeCts)
  ?, in async Task HttpTransport.SendEnvelopeAsync(Envelope envelope, CancellationToken cancellationToken)
  ?, in async Task CachingTransport.InnerProcessCacheAsync(string file, CancellationToken cancellation) x 2
  ?, in async Task CachingTransport.ProcessCacheAsync(CancellationToken cancellation)
  ?, in async Task CachingTransport.FlushAsync(CancellationToken cancellationToken)

Additionally we get this assembly information: Assembly:Sentry Version:3.16.0.0 Culture:neutral PublicKeyToken:fba2ec45388e2af0

caiofbpa commented 2 years ago

Here's a different exception that's being thrown in the same way inside the Sentry assembly:

System.AggregateException
A Task's exception(s) were not observed either by Waiting on the Task or accessing its Exception property. As a result, the unobserved exception was rethrown by the finalizer thread. ('0x00' is an invalid start of a value. LineNumber: 0 | BytePositionInLine: 0.)
System.Text.Json.JsonReaderException: '0x00' is an invalid start of a value. LineNumber: 0 | BytePositionInLine: 0.
  ?, in void ThrowHelper.ThrowJsonReaderException(ref Utf8JsonReader json, ExceptionResource resource, byte nextByte, ReadOnlySpan<byte> bytes)
  ?, in bool Utf8JsonReader.ConsumeValue(byte marker)
  ?, in bool Utf8JsonReader.ReadFirstToken(byte first)
  ?, in bool Utf8JsonReader.ReadSingleSegment()
  ?, in bool Utf8JsonReader.Read()
  ?, in void JsonDocument.Parse(ReadOnlySpan<byte> utf8JsonSpan, JsonReaderOptions readerOptions, ref MetadataDb database, ref StackRowStack stack) x 3
  ?, in JsonElement Json.Parse(byte[] json)
  ?, in async Task<IReadOnlyDictionary<string, object>> Envelope.DeserializeHeaderAsync(Stream stream, CancellationToken cancellationToken)
  ?, in async Task<Envelope> Envelope.DeserializeAsync(Stream stream, CancellationToken cancellationToken)
  ?, in async Task CachingTransport.InnerProcessCacheAsync(string file, CancellationToken cancellation) x 2
  ?, in async Task CachingTransport.ProcessCacheAsync(CancellationToken cancellation)
  ?, in async Task CachingTransport.FlushAsync(CancellationToken cancellationToken)
caiofbpa commented 2 years ago

Here's yet another exception that's being reported as a crash coming from within the Sentry assembly:

System.AggregateException
A Task's exception(s) were not observed either by Waiting on the Task or accessing its Exception property. As a result, the unobserved exception was rethrown by the finalizer thread. (Could not find file "/data/user/0/br.com.meuspedidos/files/.local/share/Sentry/EC64262B4D715A641F1FBF2FFBA5DCD08B93146A/1651680173_-6202_e2e2a80361cb47ca8c32ea45612e49d4_-1007682855.envelope")
System.IO.FileNotFoundException: Could not find file "/data/user/0/br.com.meuspedidos/files/.local/share/Sentry/EC64262B4D715A641F1FBF2FFBA5DCD08B93146A/1651680173_-6202_e2e2a80361cb47ca8c32ea45612e49d4_-1007682855.envelope"
  ?, in new FileStream(string path, FileMode mode, FileAccess access, FileShare share, int bufferSize, bool anonymous, FileOptions options) x 2
  ?, in void FileSystem.CopyFile(string sourceFullPath, string destFullPath, bool overwrite)
  ?, in void File.Copy(string sourceFileName, string destFileName, bool overwrite)
  ?, in async Task<string> CachingTransport.TryPrepareNextCacheFileAsync(CancellationToken cancellationToken)
  ?, in async Task CachingTransport.ProcessCacheAsync(CancellationToken cancellation)
  ?, in async Task CachingTransport.FlushAsync(CancellationToken cancellationToken)
lucas-zimerman commented 2 years ago

Hi Caio, Are you seeing those events being registered on Sentry.io or locally?

caiofbpa commented 2 years ago

@lucas-zimerman I'm seeing them show up on sentry.io. But I've done some more digging, it seems this is an issue with CachingTransport in sentry-dotnet actually, and I've already created an issue over there: https://github.com/getsentry/sentry-dotnet/issues/1640

khalilyamoun commented 2 years ago

We're currently facing the same issue on our Production app :(

lucas-zimerman commented 2 years ago

Despite being flagged as unhandled the above issues shouldn't crash the app. Once the fix is applied and released on Sentry .NET (https://github.com/getsentry/sentry-dotnet/issues/1640) I'll update the Xamarin SDK and release a new Version.

caiofbpa commented 2 years ago

Although those exceptions don't actually crash the app, Sentry thinks it does and that impacts our Crash Free Users and Sessions metrics. For now we've ignored those exceptions, while we wait for the new version with the fix. Thanks for the help everyone!

mattjohnsonpint commented 2 years ago

@caiofbpa - The fix has been released in Sentry 3.17.1, bundled with Sentry.Xamarin 1.4.1. Please let us know here if this resolves the issue. Thanks.