title: InterruptedIOException while using Retrofit2 with rx when retryOn
body: <p>I'm using retrofit 2 with rx-android</p>
  
  <p>I have quite complex retry logic, <strong>which partially works</strong>. I cut off irrelevant code to simplify it. Here it is:</p>
  
  <pre><code>public class RetryWithDelay implements Func1&lt;Observable&lt;? extends Throwable&gt;, Observable&lt;?&gt;&gt;, Constants {
  
  @Override
  public Observable&lt;?&gt; call(Observable&lt;? extends Throwable&gt; attempts) {
      return attempts.flatMap(new Func1&lt;Throwable, Observable&lt;?&gt;&gt;() {
  
          @Override
          public Observable&lt;?&gt; call(Throwable throwable) {
              int statusCode = 500;
              if (throwable instanceof HttpException) {
                  HttpException httpException = (HttpException) throwable;
                  statusCode = httpException.code();
              }
  
              boolean shouldRetry = shouldRetry();
  
              if (shouldRetry &amp;&amp; statusCode == 401 &amp;&amp; requiresAuthorization) {
                  LoginProvider provider = AppUtils.getExternalProvider(context);
                  switch (provider) {
                      case GOOGLE:
                          return reauthorizeGoogleProvider();
                      case FACEBOOK:
                          return reauthorizeFacebookProvider();
                      default:
                          return reauthorizeApiProvider();
                  }
              } else if (shouldRetry) {
                  return Observable.timer(Configuration.REQUEST_RETRY_DELAY_IN_SECONDS, TimeUnit.SECONDS);
              } else {
                  return Observable.error(throwable);
              }
          }
      });
  
      }
  </code></pre>
  
  <p>I have network call observable which throws 401. Then retry logic is triggered. The call looks like</p>
  
  <pre><code>observable
                  .subscribeOn(Schedulers.newThread())
                  .retryWhen(new RetryWithDelay(getActivity()))
                  .observeOn(AndroidSchedulers.mainThread())
                  .subscribe(new Subscriber&lt;MyArticles&gt;() {
                      //code removed for simplicity
                  });
  </code></pre>
  
  <p>When I get the 401 RetryWithDelay switch triggers one of three methods.
  It works fine when the user was login natively in my api, which calls:</p>
  
  <pre><code>private Observable&lt;?&gt; reauthorizeApiProvider() {
      return retrofitService.loginWithRefreshToken(data).flatMap(new Func1&lt;User, Observable&lt;?&gt;&gt;() {
          @Override
          public Observable&lt;?&gt; call(User user) {
              app.setUserInfo(UserInfo.fromUser(user));
              AppUtils.saveUserData(context, user);
              return Observable.timer(0, TimeUnit.MICROSECONDS);
          }
      });
  }
  </code></pre>
  
  <p>But for facebook or google ends up with mysterious exception: <code>java.io.InterruptedIOException: thread interrupted</code>. This is how I do it for google - same way for facebook.</p>
  
  <pre><code>private Observable&lt;?&gt; reauthorizeGoogleProvider() {
      return retrofitService.loginWithExternalProvider(LoginProvider.GOOGLE, externalAccessToken).flatMap(new Func1&lt;User, Observable&lt;?&gt;&gt;() {
          @Override
          public Observable&lt;?&gt; call(User user) {
              //some irrelevant logic
              return Observable.timer(0, TimeUnit.MICROSECONDS);
          }
      });
  }
  </code></pre>
  
  <p>There is nothing wrong with the params I pass to retrofit method. This method with the very same params is successfully used while signing in and not a part of retry logic.</p>
  
  <p>Here is full stack trace:</p>
  
  <pre><code>    java.io.InterruptedIOException: thread interrupted
  12-20 09:13:48.718 6041-6041/com.myapp.android W/System.err:     at okio.Timeout.throwIfReached(Timeout.java:145)
  12-20 09:13:48.718 6041-6041/com.myapp.android W/System.err:     at okio.Okio$1.write(Okio.java:77)
  12-20 09:13:48.718 6041-6041/com.myapp.android W/System.err:     at okio.AsyncTimeout$1.write(AsyncTimeout.java:155)
  12-20 09:13:48.718 6041-6041/com.myapp.android W/System.err:     at okio.RealBufferedSink.flush(RealBufferedSink.java:221)
  12-20 09:13:48.718 6041-6041/com.myapp.android W/System.err:     at com.squareup.okhttp.internal.http.HttpConnection.flush(HttpConnection.java:141)
  12-20 09:13:48.718 6041-6041/com.myapp.android W/System.err:     at com.squareup.okhttp.internal.http.HttpTransport.finishRequest(HttpTransport.java:52)
  12-20 09:13:48.718 6041-6041/com.myapp.android W/System.err:     at com.squareup.okhttp.internal.http.HttpEngine.readNetworkResponse(HttpEngine.java:904)
  12-20 09:13:48.718 6041-6041/com.myapp.android W/System.err:     at com.squareup.okhttp.internal.http.HttpEngine.access$300(HttpEngine.java:92)
  12-20 09:13:48.718 6041-6041/com.myapp.android W/System.err:     at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:891)
  12-20 09:13:48.718 6041-6041/com.myapp.android W/System.err:     at com.squareup.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:749)
  12-20 09:13:48.718 6041-6041/com.myapp.android W/System.err:     at com.squareup.okhttp.Call.getResponse(Call.java:268)
  12-20 09:13:48.718 6041-6041/com.myapp.android W/System.err:     at com.squareup.okhttp.Call$ApplicationInterceptorChain.proceed(Call.java:224)
  12-20 09:13:48.718 6041-6041/com.myapp.android W/System.err:     at com.myapp.android.dagger.ApiModule$1.intercept(ApiModule.java:81)
  12-20 09:13:48.718 6041-6041/com.myapp.android W/System.err:     at com.squareup.okhttp.Call$ApplicationInterceptorChain.proceed(Call.java:221)
  12-20 09:13:48.718 6041-6041/com.myapp.android W/System.err:     at com.squareup.okhttp.Call.getResponseWithInterceptorChain(Call.java:195)
  12-20 09:13:48.718 6041-6041/com.myapp.android W/System.err:     at com.squareup.okhttp.Call.execute(Call.java:79)
  12-20 09:13:48.718 6041-6041/com.myapp.android W/System.err:     at retrofit.OkHttpCall.execute(OkHttpCall.java:116)
  12-20 09:13:48.718 6041-6041/com.myapp.android W/System.err:     at retrofit.RxJavaCallAdapterFactory$CallOnSubscribe.call(RxJavaCallAdapterFactory.java:111)
  12-20 09:13:48.718 6041-6041/com.myapp.android W/System.err:     at retrofit.RxJavaCallAdapterFactory$CallOnSubscribe.call(RxJavaCallAdapterFactory.java:88)
  12-20 09:13:48.718 6041-6041/com.myapp.android W/System.err:     at rx.Observable$2.call(Observable.java:162)
  12-20 09:13:48.718 6041-6041/com.myapp.android W/System.err:     at rx.Observable$2.call(Observable.java:154)
  12-20 09:13:48.718 6041-6041/com.myapp.android W/System.err:     at rx.Observable$2.call(Observable.java:162)
  12-20 09:13:48.718 6041-6041/com.myapp.android W/System.err:     at rx.Observable$2.call(Observable.java:154)
  12-20 09:13:48.718 6041-6041/com.myapp.android W/System.err:     at rx.Observable$2.call(Observable.java:162)
  12-20 09:13:48.718 6041-6041/com.myapp.android W/System.err:     at rx.Observable$2.call(Observable.java:154)
  12-20 09:13:48.718 6041-6041/com.myapp.android W/System.err:     at rx.Observable$2.call(Observable.java:162)
  12-20 09:13:48.718 6041-6041/com.myapp.android W/System.err:     at rx.Observable$2.call(Observable.java:154)
  12-20 09:13:48.718 6041-6041/com.myapp.android W/System.err:     at rx.Observable.unsafeSubscribe(Observable.java:7710)
  12-20 09:13:48.718 6041-6041/com.myapp.android W/System.err:     at rx.internal.operators.OperatorMerge$MergeSubscriber.onNext(OperatorMerge.java:231)
  12-20 09:13:48.718 6041-6041/com.myapp.android W/System.err:     at rx.internal.operators.OperatorMerge$MergeSubscriber.onNext(OperatorMerge.java:140)
  12-20 09:13:48.718 6041-6041/com.myapp.android W/System.err:     at rx.internal.operators.OperatorMap$1.onNext(OperatorMap.java:55)
  12-20 09:13:48.718 6041-6041/com.myapp.android W/System.err:     at rx.internal.operators.OperatorMap$1.onNext(OperatorMap.java:55)
  12-20 09:13:48.718 6041-6041/com.myapp.android W/System.err:     at rx.internal.operators.OnSubscribeRedo$3$1.onNext(OnSubscribeRedo.java:307)
  12-20 09:13:48.718 6041-6041/com.myapp.android W/System.err:     at rx.internal.operators.OnSubscribeRedo$3$1.onNext(OnSubscribeRedo.java:289)
  12-20 09:13:48.718 6041-6041/com.myapp.android W/System.err:     at rx.internal.operators.NotificationLite.accept(NotificationLite.java:150)
  12-20 09:13:48.718 6041-6041/com.myapp.android W/System.err:     at rx.subjects.SubjectSubscriptionManager$SubjectObserver.emitNext(SubjectSubscriptionManager.java:254)
  12-20 09:13:48.718 6041-6041/com.myapp.android W/System.err:     at rx.subjects.BehaviorSubject.onNext(BehaviorSubject.java:160)
  12-20 09:13:48.718 6041-6041/com.myapp.android W/System.err:     at rx.internal.operators.OnSubscribeRedo$2$1.onError(OnSubscribeRedo.java:242)
  12-20 09:13:48.718 6041-6041/com.myapp.android W/System.err:     at rx.internal.operators.OperatorSubscribeOn$1$1$1.onError(OperatorSubscribeOn.java:71)
  12-20 09:13:48.718 6041-6041/com.myapp.android W/System.err:     at rx.internal.operators.OperatorMerge$MergeSubscriber.reportError(OperatorMerge.java:239)
  12-20 09:13:48.718 6041-6041/com.myapp.android W/System.err:     at rx.internal.operators.OperatorMerge$MergeSubscriber.checkTerminate(OperatorMerge.java:774)
  12-20 09:13:48.718 6041-6041/com.myapp.android W/System.err:     at rx.internal.operators.OperatorMerge$MergeSubscriber.emitLoop(OperatorMerge.java:532)
  12-20 09:13:48.718 6041-6041/com.myapp.android W/System.err:     at rx.internal.operators.OperatorMerge$MergeSubscriber.emit(OperatorMerge.java:521)
  12-20 09:13:48.718 6041-6041/com.myapp.android W/System.err:     at rx.internal.operators.OperatorMerge$InnerSubscriber.onError(OperatorMerge.java:808)
  12-20 09:13:48.718 6041-6041/com.myapp.android W/System.err:     at rx.Observable$ThrowObservable$1.call(Observable.java:9600)
  12-20 09:13:48.718 6041-6041/com.myapp.android W/System.err:     at rx.Observable$ThrowObservable$1.call(Observable.java:9590)
  12-20 09:13:48.718 6041-6041/com.myapp.android W/System.err:     at rx.Observable.unsafeSubscribe(Observable.java:7710)
  12-20 09:13:48.718 6041-6041/com.myapp.android W/System.err:     at rx.internal.operators.OperatorMerge$MergeSubscriber.onNext(OperatorMerge.java:231)
  12-20 09:13:48.718 6041-6041/com.myapp.android W/System.err:     at rx.internal.operators.OperatorMerge$MergeSubscriber.onNext(OperatorMerge.java:140)
  12-20 09:13:48.718 6041-6041/com.myapp.android W/System.err:     at rx.internal.operators.OperatorMap$1.onNext(OperatorMap.java:55)
  12-20 09:13:48.718 6041-6041/com.myapp.android W/System.err:     at retrofit.RxJavaCallAdapterFactory$CallOnSubscribe.call(RxJavaCallAdapterFactory.java:113)
  12-20 09:13:48.718 6041-6041/com.myapp.android W/System.err:     at retrofit.RxJavaCallAdapterFactory$CallOnSubscribe.call(RxJavaCallAdapterFactory.java:88)
  12-20 09:13:48.718 6041-6041/com.myapp.android W/System.err:     at rx.Observable$2.call(Observable.java:162)
  12-20 09:13:48.718 6041-6041/com.myapp.android W/System.err:     at rx.Observable$2.call(Observable.java:154)
  12-20 09:13:48.718 6041-6041/com.myapp.android W/System.err:     at rx.Observable$2.call(Observable.java:162)
  12-20 09:13:48.718 6041-6041/com.myapp.android W/System.err:     at rx.Observable$2.call(Observable.java:154)
  12-20 09:13:48.718 6041-6041/com.myapp.android W/System.err:     at rx.Observable.unsafeSubscribe(Observable.java:7710)
  12-20 09:13:48.718 6041-6041/com.myapp.android W/System.err:     at rx.internal.operators.OperatorSubscribeOn$1$1.call(OperatorSubscribeOn.java:62)
  12-20 09:13:48.718 6041-6041/com.myapp.android W/System.err:     at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:55)
  12-20 09:13:48.718 6041-6041/com.myapp.android W/System.err:     at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
  12-20 09:13:48.718 6041-6041/com.myapp.android W/System.err:     at java.util.concurrent.FutureTask.run(FutureTask.java:237)
  12-20 09:13:48.718 6041-6041/com.myapp.android W/System.err:     at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:152)
  12-20 09:13:48.718 6041-6041/com.myapp.android W/System.err:     at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:265)
  12-20 09:13:48.718 6041-6041/com.myapp.android W/System.err:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
  12-20 09:13:48.718 6041-6041/com.myapp.android W/System.err:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
  12-20 09:13:48.718 6041-6041/com.myapp.android W/System.err:     at java.lang.Thread.run(Thread.java:818)
  </code></pre>
  
  <p>Please advise</p>
  
  <p>EDIT: Investigations shows that it's somehow connected to http method. <code>loginWithRefreshToken</code> is <code>POST</code> and <code>loginWithExternalProvider</code> is <code>GET</code>. Works when changed ti POST. But that's stupid. Need real solution.</p>