Bug 50210 - GC causes app to crash after ModernHttpClient throws an exception
Summary: GC causes app to crash after ModernHttpClient throws an exception
Status: RESOLVED UPSTREAM
Alias: None
Product: Android
Classification: Xamarin
Component: General (show other bugs)
Version: 7.0 (C8)
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Jonathan Pryor
URL:
Depends on:
Blocks:
 
Reported: 2016-12-16 13:16 UTC by Daniel
Modified: 2017-06-13 21:51 UTC (History)
5 users (show)

See Also:
Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Simple test project for reproducing the issue (2.23 MB, application/x-zip-compressed)
2016-12-16 13:16 UTC, Daniel
Details

Description Daniel 2016-12-16 13:16:40 UTC
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 7.1.0.13). 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 6.1.0.71) or Cycle 9 (Xamarin.Android 7.1.0.13) releases the app doesn't crash.
Comment 1 Daniel 2016-12-16 13:29:14 UTC
Just noticed that this may be a duplicate of: https://bugzilla.xamarin.com/show_bug.cgi?id=45003
Comment 2 David Laundav 2017-02-06 11:59:39 UTC
Any news in regards to this issue?
Comment 3 Anton Morozov 2017-02-15 10:26:04 UTC
The bug is caused by ModernHttp setting a Java exception into a Task.

See this comment in in ModernHttp repo: 
https://github.com/paulcbetts/ModernHttpClient/issues/229?_pjax=%23js-repo-pjax-container#issuecomment-253214125

It can be easily fixed in ModernHttp code.
Comment 4 Cody Beyer (MSFT) 2017-06-13 21:51:13 UTC
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

Note You need to log in before you can comment on or make changes to this bug.