{"action":"created","issue":{"url":"https://api.github.com/repos/square/retrofit/issues/1214","labels_url":"https://api.github.com/repos/square/retrofit/issues/1214/labels{/name}","comments_url":"https://api.github.com/repos/square/retrofit/issues/1214/comments","events_url":"https://api.github.com/repos/square/retrofit/issues/1214/events","html_url":"https://github.com/square/retrofit/issues/1214","id":112505509,"number":1214,"title":"Retrofit + RxJava: Fatal Exception thrown on Scheduler.Worker thread.","user":{"login":"sureshs592","id":5411946,"avatar_url":"https://avatars.githubusercontent.com/u/5411946?v=3","gravatar_id":"","url":"https://api.github.com/users/sureshs592","html_url":"https://github.com/sureshs592","followers_url":"https://api.github.com/users/sureshs592/followers","following_url":"https://api.github.com/users/sureshs592/following{/other_user}","gists_url":"https://api.github.com/users/sureshs592/gists{/gist_id}","starred_url":"https://api.github.com/users/sureshs592/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sureshs592/subscriptions","organizations_url":"https://api.github.com/users/sureshs592/orgs","repos_url":"https://api.github.com/users/sureshs592/repos","events_url":"https://api.github.com/users/sureshs592/events{/privacy}","received_events_url":"https://api.github.com/users/sureshs592/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-10-21T03:35:12Z","updated_at":"2015-10-28T14:53:28Z","closed_at":null,"body":"Hello folks! I'm encountering this fatal crash under very specific circumstances. Gets triggered when there's bad network connectivity and the request eventually times out. What's peculiar is I do have an `ErrorHandler` implementation set in the `RestAdapter` object.\r\n\r\n#### More information about my current app setup:\r\n- retrofit `v1.9.0`\r\n- okhttp-urlconnection `v2.5.0`\r\n- rxandroid `v0.24.0`\r\n- Snippet of my RestAdapter initialisation:\r\n```java\r\nrestAdapter = new RestAdapter.Builder().setEndpoint(baseUrl)\r\n          .setConverter(new GsonConverter(gson))\r\n          .setLogLevel(RestAdapter.LogLevel.HEADERS)\r\n          .setClient(new OkClient(okHttpClient))\r\n          .setRequestInterceptor(new NNRequestInterceptor())\r\n          .setErrorHandler(new RetrofitErrorHandler(mContext))\r\n          .build();\r\n```\r\n- Snippet of my ErrorHandler implementation:\r\n```java\r\npublic class RetrofitErrorHandler implements ErrorHandler {\r\n\r\n  @Override public Throwable handleError(RetrofitError cause) {\r\n    try {\r\n      ...\r\n      return new NetworkRequestException(cause, errorDescription);\r\n    } catch (Exception e) {\r\n      Timber.e(e, \"Error while handling Retrofit error\");\r\n      return e;\r\n    }\r\n  }\r\n}\r\n```\r\n\r\nHave attached the stack trace with some notes below. I'm trying to reproduce this issue more reliably. Will update on this thread if I manage to do so. Please let me know if you need any other information. Looking forward to any help/inputs on this!\r\n\r\n#### Stack trace\r\nWould like to highlight two things in the stack trace here:\r\n- Error seems to originate from this line: `com.squareup.okhttp.internal.Network$1.resolveInetAddresses(Network.java:29)`\r\n- Also seems to pass through my error handler: `co.ninetynine.android.core.api.RetrofitErrorHandler.handleError(RetrofitErrorHandler.java:37)`\r\n\r\n```\r\njava.lang.IllegalStateException: Fatal Exception thrown on Scheduler.Worker thread.\r\n       at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:54)\r\n       at android.os.Handler.handleCallback(Handler.java:739)\r\n       at android.os.Handler.dispatchMessage(Handler.java:95)\r\n       at android.os.Looper.loop(Looper.java:145)\r\n       at android.app.ActivityThread.main(ActivityThread.java:5938)\r\n       at java.lang.reflect.Method.invoke(Method.java)\r\n       at java.lang.reflect.Method.invoke(Method.java:372)\r\n       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1389)\r\n       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1184)\r\nCaused by: d.b.i: Error occurred when trying to propagate error to Observer.onError\r\n       at rx.observers.SafeSubscriber._onError(SafeSubscriber.java:201)\r\n       at rx.observers.SafeSubscriber.onError(SafeSubscriber.java:111)\r\n       at rx.internal.operators.NotificationLite.accept(NotificationLite.java:147)\r\n       at rx.internal.operators.OperatorObserveOn$ObserveOnSubscriber.pollQueue(OperatorObserveOn.java:177)\r\n       at rx.internal.operators.OperatorObserveOn$ObserveOnSubscriber.access$000(OperatorObserveOn.java:65)\r\n       at rx.internal.operators.OperatorObserveOn$ObserveOnSubscriber$2.call(OperatorObserveOn.java:153)\r\n       at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:47)\r\n       at android.os.Handler.handleCallback(Handler.java:739)\r\n       at android.os.Handler.dispatchMessage(Handler.java:95)\r\n       at android.os.Looper.loop(Looper.java:145)\r\n       at android.app.ActivityThread.main(ActivityThread.java:5938)\r\n       at java.lang.reflect.Method.invoke(Method.java)\r\n       at java.lang.reflect.Method.invoke(Method.java:372)\r\n       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1389)\r\n       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1184)\r\nCaused by: d.b.a: 2 exceptions occurred. \r\n       at rx.observers.SafeSubscriber._onError(SafeSubscriber.java:201)\r\n       at rx.observers.SafeSubscriber.onError(SafeSubscriber.java:111)\r\n       at rx.internal.operators.NotificationLite.accept(NotificationLite.java:147)\r\n       at rx.internal.operators.OperatorObserveOn$ObserveOnSubscriber.pollQueue(OperatorObserveOn.java:177)\r\n       at rx.internal.operators.OperatorObserveOn$ObserveOnSubscriber.access$000(OperatorObserveOn.java:65)\r\n       at rx.internal.operators.OperatorObserveOn$ObserveOnSubscriber$2.call(OperatorObserveOn.java:153)\r\n       at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:47)\r\n       at android.os.Handler.handleCallback(Handler.java:739)\r\n       at android.os.Handler.dispatchMessage(Handler.java:95)\r\n       at android.os.Looper.loop(Looper.java:145)\r\n       at android.app.ActivityThread.main(ActivityThread.java:5938)\r\n       at java.lang.reflect.Method.invoke(Method.java)\r\n       at java.lang.reflect.Method.invoke(Method.java:372)\r\n       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1389)\r\n       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1184)\r\nCaused by: d.b.c: Chain of Causes for CompositeException In Order Received =>\r\n       at com.crashlytics.android.core.SessionDataWriter.getEventAppExecutionExceptionSize(SessionDataWriter.java:597)\r\n       at com.crashlytics.android.core.SessionDataWriter.getEventAppExecutionExceptionSize(SessionDataWriter.java:600)\r\n       at com.crashlytics.android.core.SessionDataWriter.getEventAppExecutionExceptionSize(SessionDataWriter.java:600)\r\n       at com.crashlytics.android.core.SessionDataWriter.getEventAppExecutionSize(SessionDataWriter.java:533)\r\n       at com.crashlytics.android.core.SessionDataWriter.getEventAppSize(SessionDataWriter.java:492)\r\n       at com.crashlytics.android.core.SessionDataWriter.getSessionEventSize(SessionDataWriter.java:473)\r\n       at com.crashlytics.android.core.SessionDataWriter.writeSessionEvent(SessionDataWriter.java:195)\r\n       at com.crashlytics.android.core.CrashlyticsUncaughtExceptionHandler.writeSessionEvent(CrashlyticsUncaughtExceptionHandler.java:1038)\r\n       at com.crashlytics.android.core.CrashlyticsUncaughtExceptionHandler.writeFatal(CrashlyticsUncaughtExceptionHandler.java:395)\r\n       at com.crashlytics.android.core.CrashlyticsUncaughtExceptionHandler.handleUncaughtException(CrashlyticsUncaughtExceptionHandler.java:298)\r\n       at com.crashlytics.android.core.CrashlyticsUncaughtExceptionHandler.access$102(CrashlyticsUncaughtExceptionHandler.java:56)\r\n       at com.crashlytics.android.core.CrashlyticsUncaughtExceptionHandler$7.call(CrashlyticsUncaughtExceptionHandler.java:278)\r\n       at com.crashlytics.android.core.CrashlyticsUncaughtExceptionHandler$7.call(CrashlyticsUncaughtExceptionHandler.java:275)\r\n       at java.util.concurrent.FutureTask.run(FutureTask.java:237)\r\n       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)\r\n       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)\r\n       at io.fabric.sdk.android.services.common.ExecutorUtils$1$1.onRun(ExecutorUtils.java:75)\r\n       at io.fabric.sdk.android.services.common.BackgroundPriorityRunnable.run(BackgroundPriorityRunnable.java:30)\r\n       at java.lang.Thread.run(Thread.java:818)\r\nCaused by: co.ninetynine.android.core.api.e: Please check your connection…\r\n       at co.ninetynine.android.core.api.RetrofitErrorHandler.handleError(RetrofitErrorHandler.java:37)\r\n       at retrofit.RxSupport$2.run(RxSupport.java:59)\r\n       at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)\r\n       at java.util.concurrent.FutureTask.run(FutureTask.java:237)\r\n       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)\r\n       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)\r\n       at retrofit.Platform$Android$2$1.run(Platform.java:142)\r\n       at java.lang.Thread.run(Thread.java:818)\r\nCaused by: retrofit.RetrofitError: Unable to resolve host \"www.99.co\": No address associated with hostname\r\n       at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:395)\r\n       at retrofit.RestAdapter$RestHandler.access$100(RestAdapter.java:220)\r\n       at retrofit.RestAdapter$RestHandler$1.invoke(RestAdapter.java:265)\r\n       at retrofit.RxSupport$2.run(RxSupport.java:55)\r\n       at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)\r\n       at java.util.concurrent.FutureTask.run(FutureTask.java:237)\r\n       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)\r\n       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)\r\n       at retrofit.Platform$Android$2$1.run(Platform.java:142)\r\n       at java.lang.Thread.run(Thread.java:818)\r\nCaused by: java.net.UnknownHostException: Unable to resolve host \"www.99.co\": No address associated with hostname\r\n       at java.net.InetAddress.lookupHostByName(InetAddress.java:457)\r\n       at java.net.InetAddress.getAllByNameImpl(InetAddress.java:252)\r\n       at java.net.InetAddress.getAllByName(InetAddress.java:215)\r\n       at com.squareup.okhttp.internal.Network$1.resolveInetAddresses(Network.java:29)\r\n       at com.squareup.okhttp.internal.http.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:187)\r\n       at com.squareup.okhttp.internal.http.RouteSelector.nextProxy(RouteSelector.java:156)\r\n       at com.squareup.okhttp.internal.http.RouteSelector.next(RouteSelector.java:98)\r\n       at com.squareup.okhttp.internal.http.HttpEngine.createNextConnection(HttpEngine.java:344)\r\n       at com.squareup.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:327)\r\n       at com.squareup.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:245)\r\n       at com.squareup.okhttp.Call.getResponse(Call.java:267)\r\n       at com.squareup.okhttp.Call$ApplicationInterceptorChain.proceed(Call.java:224)\r\n       at com.squareup.okhttp.Call.getResponseWithInterceptorChain(Call.java:195)\r\n       at com.squareup.okhttp.Call.execute(Call.java:79)\r\n       at retrofit.client.OkClient.execute(OkClient.java:53)\r\n       at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:326)\r\n       at retrofit.RestAdapter$RestHandler.access$100(RestAdapter.java:220)\r\n       at retrofit.RestAdapter$RestHandler$1.invoke(RestAdapter.java:265)\r\n       at retrofit.RxSupport$2.run(RxSupport.java:55)\r\n       at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)\r\n       at java.util.concurrent.FutureTask.run(FutureTask.java:237)\r\n       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)\r\n       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)\r\n       at retrofit.Platform$Android$2$1.run(Platform.java:142)\r\n       at java.lang.Thread.run(Thread.java:818)\r\nCaused by: android.system.GaiException: android_getaddrinfo failed: EAI_NODATA (No address associated with hostname)\r\n       at libcore.io.Posix.android_getaddrinfo(Posix.java)\r\n       at libcore.io.ForwardingOs.android_getaddrinfo(ForwardingOs.java:55)\r\n       at java.net.InetAddress.lookupHostByName(InetAddress.java:438)\r\n       at java.net.InetAddress.getAllByNameImpl(InetAddress.java:252)\r\n       at java.net.InetAddress.getAllByName(InetAddress.java:215)\r\n       at com.squareup.okhttp.internal.Network$1.resolveInetAddresses(Network.java:29)\r\n       at com.squareup.okhttp.internal.http.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:187)\r\n       at com.squareup.okhttp.internal.http.RouteSelector.nextProxy(RouteSelector.java:156)\r\n       at com.squareup.okhttp.internal.http.RouteSelector.next(RouteSelector.java:98)\r\n       at com.squareup.okhttp.internal.http.HttpEngine.createNextConnection(HttpEngine.java:344)\r\n       at com.squareup.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:327)\r\n       at com.squareup.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:245)\r\n       at com.squareup.okhttp.Call.getResponse(Call.java:267)\r\n       at com.squareup.okhttp.Call$ApplicationInterceptorChain.proceed(Call.java:224)\r\n       at com.squareup.okhttp.Call.getResponseWithInterceptorChain(Call.java:195)\r\n       at com.squareup.okhttp.Call.execute(Call.java:79)\r\n       at retrofit.client.OkClient.execute(OkClient.java:53)\r\n       at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:326)\r\n       at retrofit.RestAdapter$RestHandler.access$100(RestAdapter.java:220)\r\n       at retrofit.RestAdapter$RestHandler$1.invoke(RestAdapter.java:265)\r\n       at retrofit.RxSupport$2.run(RxSupport.java:55)\r\n       at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)\r\n       at java.util.concurrent.FutureTask.run(FutureTask.java:237)\r\n       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)\r\n       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)\r\n       at retrofit.Platform$Android$2$1.run(Platform.java:142)\r\n       at java.lang.Thread.run(Thread.java:818)\r\n```"},"comment":{"url":"https://api.github.com/repos/square/retrofit/issues/comments/151870997","html_url":"https://github.com/square/retrofit/issues/1214#issuecomment-151870997","issue_url":"https://api.github.com/repos/square/retrofit/issues/1214","id":151870997,"user":{"login":"sureshs592","id":5411946,"avatar_url":"https://avatars.githubusercontent.com/u/5411946?v=3","gravatar_id":"","url":"https://api.github.com/users/sureshs592","html_url":"https://github.com/sureshs592","followers_url":"https://api.github.com/users/sureshs592/followers","following_url":"https://api.github.com/users/sureshs592/following{/other_user}","gists_url":"https://api.github.com/users/sureshs592/gists{/gist_id}","starred_url":"https://api.github.com/users/sureshs592/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sureshs592/subscriptions","organizations_url":"https://api.github.com/users/sureshs592/orgs","repos_url":"https://api.github.com/users/sureshs592/repos","events_url":"https://api.github.com/users/sureshs592/events{/privacy}","received_events_url":"https://api.github.com/users/sureshs592/received_events","type":"User","site_admin":false},"created_at":"2015-10-28T14:53:27Z","updated_at":"2015-10-28T14:53:27Z","body":"Hey @scana some good news. Think I've found the cause of this fatal error. After debugging this issue, I noticed that this crash was occurring only in **one** of my API calls. The app would crash whenever that particular call hit a network error. Disabling that call seems to solve the problem.\r\n\r\nThink RxJava didn't do a very good job of showing us the entire chain of exceptions here. From what I observe, it looks like this fatal crash originates from the code running in the `onError()` method of the end subscriber for the entire operation. i.e. The code that runs **after** Retrofit passes the error through the catch all `ErrorHandler` implementation (which was this class called `RetrofitErrorHandler` in my case).\r\n\r\nWhat could have caused the crash? I can't confirm yet. Have temporarily disabled the faulty call for now until I fix it. But I'm suspecting the `Response` variable in the `RetrofitError` cause object is `null` in the event of a `NETWORK` error. (Makes sense if you think about it. There was a network issue, so Retrofit couldn't really get a response as such). I was accessing the body/status code of the response without checking if the `Response` object itself was `null`. I suspect that might have triggered a `NullPointerException`.\r\n\r\nWill let you know again if this hypothesis is correct once I fix the code! (Will be very soon) Will close this issue once I find a working fix."}}