Created attachment 18909 [details]
Simple test project for reproducing the issue
We have an app that is using ModernHttpClient to make HTTP requests. We've noticed that if ModernHttpClient throws an exception (that we catch) the app will crash the next time that a garbage collect is performed. When the app crashes it logs a "JNI DETECTED ERROR IN APPLICATION: use of invalid jobject 0x7f58cec5e0" error and a huge stack trace.
This only seems to happen on Cycle 8 releases (not on Cycle 7 or the most recent Cycle 9 release, Xamarin.Android 22.214.171.124). Also, it only happens when ModernHttpClient is used. If I switch to HttpClientHandler or AndroidClientHandler the app doesn't crash.
I've broken out the code from our project to a simple test project.
Steps to reproduce:
1. Put the device in airplane mode
2. Launch the app
3. Press the "Send get request" button
a. An exception will be thrown since the device doesn't have a connection.
4. Press the "Send get request" button a second time
5. Press the "Manual GC call" button
In the test project that I've attached I need to send two requests for the issue to occur, in our real project the issue occurs after one request.
I don't know if this is a bug in Xamarin or in ModernHttpClient, but even if it is a bug in ModernHttpClient I would like to know why it only occurs in Cycle 8 releases. If I try the same thing in Cycle 7 (Xamarin.Android 126.96.36.199) or Cycle 9 (Xamarin.Android 188.8.131.52) releases the app doesn't crash.
Just noticed that this may be a duplicate of: https://bugzilla.xamarin.com/show_bug.cgi?id=45003
Any news in regards to this issue?
The bug is caused by ModernHttp setting a Java exception into a Task.
See this comment in in ModernHttp repo:
It can be easily fixed in ModernHttp code.
This has been fixed in a fork of ModernHTTPClient, however that fork has not turned into a PR as far as I can tell.
Please see https://github.com/Youscribe/ModernHttpClient/tree/hotfix/cycle8-issue