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

OkHttp (used by UrlConnection) might start a new Thread when reading response #1907

Closed
william-ferguson-au opened this issue Oct 8, 2015 · 9 comments

Comments

@william-ferguson-au
Copy link

I'm the maintainer for ACRA (Android Crash Reporter) and as part of the migration to using UrlConnection instead of the Apache Http library we are running foul of OkHttp potentially starting a new Thread during runtime shutdown when we attempt to read a HTTP response..

See ACRA/acra#313

Is there any way of ensuring that OkHttp doesn't start a new Thread?

D/ACRA﹕ Connect to https://testapps.cloudant.com/acra-testapp/_design/acra-storage/_update/report
 09-28 22:35:09.235 16507-16536/? E/ACRA﹕ ACRA caught a InternalError for com.blogspot.test.testapp
 java.lang.InternalError: Thread starting during runtime shutdown
 at java.lang.Thread.nativeCreate(Native Method)
 at java.lang.Thread.start(Thread.java:1063)
 at java.util.concurrent.ThreadPoolExecutor.addWorker(ThreadPoolExecutor.java:921)
 at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1337)
 at com.android.okhttp.ConnectionPool.addConnection(ConnectionPool.java:208)
 at com.android.okhttp.ConnectionPool.recycle(ConnectionPool.java:198)
 at com.android.okhttp.OkHttpClient$1.recycle(OkHttpClient.java:111)
 at com.android.okhttp.internal.http.HttpConnection$AbstractSource.endOfInput(HttpConnection.java:377)
 at com.android.okhttp.internal.http.HttpConnection$FixedLengthSource.read(HttpConnection.java:426)
 at com.android.okhttp.okio.RealBufferedSource$1.read(RealBufferedSource.java:349)
 at java.io.InputStream.read(InputStream.java:162)
 at com.a.a.a.a.a(SourceFile:238)
 at com.a.a.a.a.a(SourceFile:123)
 at com.a.a.k.run(SourceFile:112)

@swankjesse
Copy link
Member

No, there's no such mechanism. When does Android shutdown the runtime?!

@william-ferguson-au
Copy link
Author

I suspect Android is marking it as shutdown as soon as an unchecked Exception or Error is not handled by the app.

ACRA installs an UncaughtExceptionHandler in Application#onCreate. We send the HttpRequest from the UncaughtExceptionHandler. I can only presume that the Android framework is intercepting in some fashion to mark the VM as shutdown.

@william-ferguson-au
Copy link
Author

So it's sounding like ACRA won't be able to UrlConnection to send Http requests since UrlConnection is using OkHttp under the covers. Does that sound correct?

@swankjesse
Copy link
Member

You're probably better off writing the crash information to disk somewhere, and picking it up when the app relaunches. The crash might be an OutOfMemoryError, for example, and you're also going to need to allocate a bunch of memory to make an HTTP request.

@swankjesse
Copy link
Member

(No action for us here.)

@william-ferguson-au
Copy link
Author

We do write the crash info to disk as a fall back.
But sending requires the app to relaunch which doesn't automatically occur for all Android versions.
One action for OkHttp could be to allow a minimum nr of threads in the pool instead of always collapsing to zero.

@JakeWharton
Copy link
Member

This is a dupe of a really, really old issue. I'd have to search to find it.

On Wed, Oct 7, 2015, 10:06 PM William Ferguson notifications@github.com
wrote:

We do write the crash info to disk as a fall back.
But sending requires the app to relaunch which doesn't automatically occur
for all Android versions.
One action for OkHttp could be to allow a minimum nr of threads in the
pool instead of always collapsing to zero.


Reply to this email directly or view it on GitHub
#1907 (comment).

@JakeWharton
Copy link
Member

#1153

@william-ferguson-au
Copy link
Author

Thanks for the reference Jake.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants