Skip to content

BufferedFileStreamStrategy.ReadAsync throws Arg_InvalidOperationException when EnableLLVM == true #104167

Description

@jamescrosswell

Android application type

.NET Android (net7.0-android, net8.0-android, etc.)

Affected platform version

.NET 8.0.0

Description

We have a customer using the Sentry SDK in their MAUI application. One piece of functionality they've built sends log files through to a Sentry server. A background task in the Sentry API is calling FileStream.ReadAsync to enable this.

If the application is compiled with the build property <EnableLLVM>true</EnableLLVM> then frequently the logs are not sent to Sentry. Trawling through the diagnostic logs, it appears the BufferedFileStreamStrategy.ReadAsync method is throwing an Arg_InvalidOperationException, but it's not clear why.

See full discussion (including the source code to an app that allows this issue to be reproduced) at:

Steps to Reproduce

Steps to reproduce described here.

Did you find any workaround?

No. The customer needs to enable EnableLLVM for performance reasons.

Relevant log output

2024-02-15 14:50:56.008  9130-9159  DOTNET                  com.companyname.sentrydebughelper    I    Debug: Android: Serializing object: { 	"reportType": "SendLogs" }
2024-02-15 14:50:56.010  9130-9209  DOTNET                  com.companyname.sentrydebughelper    I  Warning: Failed to serialize envelope item
                                                                                                    System.InvalidOperationException: Arg_InvalidOperationException
2024-02-15 14:50:56.010  9130-9209  DOTNET                  com.companyname.sentrydebughelper    I     at System.Threading.Tasks.Sources.ManualResetValueTaskSourceCore`1[[System.Int64, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].GetStatus(Int16 )
                                                                                                       at Microsoft.Win32.SafeHandles.SafeFileHandle.ThreadPoolValueTaskSource.GetStatus(Int16 )
                                                                                                       at System.IO.Strategies.BufferedFileStreamStrategy.ReadAsync(Byte[] , Int32 , Int32 , CancellationToken )
2024-02-15 14:50:56.010  9130-9209  DOTNET                  com.companyname.sentrydebughelper    I     at System.IO.FileStream.ReadAsync(Byte[] , Int32 , Int32 , CancellationToken )
                                                                                                       at Sentry.Internal.PartialStream.ReadAsync(Byte[] , Int32 , Int32 , CancellationToken )
2024-02-15 14:50:56.010  9130-9209  DOTNET                  com.companyname.sentrydebughelper    I     at System.IO.Stream.<CopyToAsync>g__Core|27_0(Stream , Stream , Int32 , CancellationToken )
                                                                                                       at Sentry.Protocol.Envelopes.EnvelopeItem.BufferPayloadAsync(IDiagnosticLogger , CancellationToken )
                                                                                                       at Sentry.Protocol.Envelopes.EnvelopeItem.SerializeAsync(Stream , IDiagnosticLogger , CancellationToken )
2024-02-15 14:50:56.010  9130-9209  DOTNET                  com.companyname.sentrydebughelper    I     at Sentry.Protocol.Envelopes.Envelope.SerializeAsync(Stream , IDiagnosticLogger , ISystemClock , CancellationToken )

Activity

  1. vargaz commented on Feb 22, 2024

    @vargaz
    Contributor

    Is this reproducible with a sample which just calls FileStream.ReadAsync ?

  2. jamescrosswell commented on Mar 3, 2024

    @jamescrosswell
    Author

    Is this reproducible with a sample which just calls FileStream.ReadAsync ?

    @pierre-galaup do you think you could try to create a simplified version of your demo app that has LLVM enabled and loops to try to read some files (async) and stream these off into the void (just as a way to verify this is genuinely coming from FileStream.ReadAsync when LLVM is enabled)? If not, I might be able to try but I can't prioritise this right now (it will be some weeks before I can do this).

  3. tranb3r commented on May 13, 2024

    @tranb3r

    @jamescrosswell @vargaz @pierre-galaup
    I'm having the same issue with Sentry when enabling LLVM.
    I've easily reproduced it in a sample app which just calls FileStream.ReadAsync.
    Could this be fixed? Is there a workaround?

  4. tranb3r commented on May 14, 2024

    @tranb3r
  5. tranb3r commented on Jun 27, 2024

    @tranb3r

    @grendello @vargaz @lamdageek
    Any update?
    This is impacting the Sentry SDK, and no workaround seems possible.

  6. lambdageek commented on Jun 28, 2024

    @lambdageek
    Member
  7. steveisok commented on Jun 28, 2024

    @steveisok
    Member

    @grendello @vargaz @lamdageek Any update? This is impacting the Sentry SDK, and no workaround seems possible.

    @tranb3r no update yet. We'll share when we have more details.

  8. lambdageek commented on Jun 28, 2024

    @lambdageek
    Member

    Might be related to #100527 we should try the upcoming servicing release to see if the AOT compiler fixes there will address this one, too

  9. ghost added
    needs-area-labelAn area label is needed to ensure this gets routed to the appropriate area owners
    on Jun 28, 2024
  10. 4 remaining items

  11. removed
    untriagedNew issue has not been triaged by the area owner
    on Jun 28, 2024
  12. added this to the 9.0.0 milestone on Jun 28, 2024
  13. removed
    needs-area-labelAn area label is needed to ensure this gets routed to the appropriate area owners
    on Jun 28, 2024
  14. tranb3r commented on Jul 22, 2024

    @tranb3r

    I've tested 8.0.7 but I still get the error when running my repro app.
    Could somebody please double-check?

  15. fanyang-mono commented on Jul 22, 2024

    @fanyang-mono
    Member

    @tranb3r Thanks for validating. We would need to look into it further.

  16. tranb3r commented on Aug 5, 2024

    @tranb3r

    Any update? Thanks

  17. modified the milestones: 9.0.0, 10.0.0 on Sep 23, 2024
  18. tranb3r commented on Oct 10, 2024

    @tranb3r

    Still not working in net9-rc2.

  19. tranb3r commented on Dec 2, 2024

    @tranb3r

    Still happening with net9 (net-android 35.0.7)

  20. redwolf2 commented on Jul 8, 2025

    @redwolf2

    Still happens with MAUI 9.0.81.

  21. jamescrosswell commented on Jul 8, 2025

    @jamescrosswell
    Author

    This is impacting the Sentry SDK, and no workaround seems possible.

    There is a workaround implemented in Sentry that is suggested by these new analyser warnings:

    ... if you can modify the code that is making the call to ReadAsync that is.

  22. modified the milestones: 10.0.0, Future on Aug 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions