okhttp: NoSuchElementException in RouteSelector

okhttp 3.7.0 retrofit 2.2.0

All device brands and Android versions are reporting this issue.

It happened for example after I tapped a notification, the app then makes a GET which ended in this exception. It didn’t happen when I recreated the scenario. Device was Pixel, Android 7.1.2, on WLAN.

java.util.NoSuchElementException
  at okhttp3.internal.connection.RouteSelector.next(RouteSelector.java:77)
  at okhttp3.internal.connection.StreamAllocation.findConnection(StreamAllocation.java:171)
  at okhttp3.internal.connection.StreamAllocation.findHealthyConnection(StreamAllocation.java:121)
  at okhttp3.internal.connection.StreamAllocation.newStream(StreamAllocation.java:100)
  at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:42)
  at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
  at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
  at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)
  at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
  at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
  at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
  at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
  at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:120)
  at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
  at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
  at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:211)
  at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
  at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
  at com.readystatesoftware.chuck.ChuckInterceptor.intercept(ChuckInterceptor.java:167)
  at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
  at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
  at com.myownpackage.manager.OkHttpManager$AuthenticationInterceptor.intercept(OkHttpManager.java:135)
  at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
  at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
  at com.myownpackage.manager.OkHttpManager$NetworkLoggingInterceptor.intercept(OkHttpManager.java:190)
  at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
  at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
  at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:185)
  at okhttp3.RealCall.execute(RealCall.java:69)
  at retrofit2.OkHttpCall.execute(OkHttpCall.java:174)
  at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall.execute(ExecutorCallAdapterFactory.java:89)
  at com.myownpackage.ui.ProfileFragment$11.doInBackground(ProfileFragment.java:516)
  at com.myownpackage.ui.ProfileFragment$11.doInBackground(ProfileFragment.java:511)
  at com.nanotasks.AbstractTask.doInBackground(AbstractTask.java:18)
  at com.nanotasks.AbstractTask.doInBackground(AbstractTask.java:7)
  at android.os.AsyncTask$2.call(AsyncTask.java:305)
  at java.util.concurrent.FutureTask.run(FutureTask.java:237)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
  at java.lang.Thread.run(Thread.java:761)

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Reactions: 14
  • Comments: 65 (4 by maintainers)

Commits related to this issue

Most upvoted comments

Fix released as OkHttp 3.8.1.

Fatal Exception: java.util.NoSuchElementException
       at okhttp3.internal.connection.RouteSelector.next + 75(RouteSelector.java:75)
       at okhttp3.internal.connection.ExchangeFinder.findConnection + 187(ExchangeFinder.java:187)
       at okhttp3.internal.connection.ExchangeFinder.findHealthyConnection + 108(ExchangeFinder.java:108)
       at okhttp3.internal.connection.ExchangeFinder.find + 88(ExchangeFinder.java:88)
       at okhttp3.internal.connection.Transmitter.newExchange + 169(Transmitter.java:169)
       at okhttp3.internal.connection.ConnectInterceptor.intercept + 41(ConnectInterceptor.java:41)
       at okhttp3.internal.http.RealInterceptorChain.proceed + 142(RealInterceptorChain.java:142)
       at okhttp3.internal.http.RealInterceptorChain.proceed + 117(RealInterceptorChain.java:117)
       at okhttp3.internal.cache.CacheInterceptor.intercept + 94(CacheInterceptor.java:94)
       at okhttp3.internal.http.RealInterceptorChain.proceed + 142(RealInterceptorChain.java:142)
       at okhttp3.internal.http.RealInterceptorChain.proceed + 117(RealInterceptorChain.java:117)
       at okhttp3.internal.http.BridgeInterceptor.intercept + 93(BridgeInterceptor.java:93)
       at okhttp3.internal.http.RealInterceptorChain.proceed + 142(RealInterceptorChain.java:142)
       at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept + 88(RetryAndFollowUpInterceptor.java:88)
       at okhttp3.internal.http.RealInterceptorChain.proceed + 142(RealInterceptorChain.java:142)
       at okhttp3.internal.http.RealInterceptorChain.proceed + 117(RealInterceptorChain.java:117)
       at applicationId.network.RetrofitApiManager.lambda$getClient$1 + 45(RetrofitApiManager.java:45)
       at [applicationId.network.-$$Lambda$RetrofitApiManager$T8u62N07bPZuTSKTMwG8MsiSwAU.intercept(Unknown Source)
       at okhttp3.internal.http.RealInterceptorChain.proceed + 142(RealInterceptorChain.java:142)
       at okhttp3.internal.http.RealInterceptorChain.proceed + 117(RealInterceptorChain.java:117)
       at okhttp3.logging.HttpLoggingInterceptor.intercept + 223(HttpLoggingInterceptor.java:223)
       at okhttp3.internal.http.RealInterceptorChain.proceed + 142(RealInterceptorChain.java:142)
       at okhttp3.internal.http.RealInterceptorChain.proceed + 117(RealInterceptorChain.java:117)
       at okhttp3.RealCall.getResponseWithInterceptorChain + 221(RealCall.java:221)
       at okhttp3.RealCall$AsyncCall.execute + 172(RealCall.java:172)
       at okhttp3.internal.NamedRunnable.run + 32(NamedRunnable.java:32)
       at java.util.concurrent.ThreadPoolExecutor.runWorker + 1167(ThreadPoolExecutor.java:1167)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run + 641(ThreadPoolExecutor.java:641)
       at java.lang.Thread.run + 764(Thread.java:764)](url)

version 3.14.2

I got the same issue with okhttp = “4.9.0” and retrofit = “2.9.0”

Fatal Exception: java.util.NoSuchElementException at okhttp3.internal.connection.RouteSelector.next(RouteSelector.java:63) at okhttp3.internal.connection.ExchangeFinder.findConnection(ExchangeFinder.java:205) at okhttp3.internal.connection.ExchangeFinder.findHealthyConnection(ExchangeFinder.java:106) at okhttp3.internal.connection.ExchangeFinder.find(ExchangeFinder.java:74) at okhttp3.internal.connection.RealCall.initExchange$okhttp(RealCall.java:255) at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:32) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:109) at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:95) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:109) at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:83) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:109) at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:76) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:109) at com.sephora.framework.api.webservice.dotcom.akamaibot.AkamaiBotInterceptor.intercept(AkamaiBotInterceptor.java:9) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:109) at com.sephora.framework.firebase.CrashlyticsInterceptor.intercept(CrashlyticsInterceptor.java:23) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:109) at com.sephora.framework.api.webservice.dotcom.request.interceptor.behaviour.BehaviourInterceptor.intercept(BehaviourInterceptor.java:39) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:109) at com.sephora.framework.api.webservice.dotcom.request.interceptor.AddUserAgentInterceptor.intercept(AddUserAgentInterceptor.java:23) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:109) at com.sephora.framework.api.webservice.dotcom.request.interceptor.AddCustomHeadersInterceptor.intercept(AddCustomHeadersInterceptor.java:17) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:109) at okhttp3.internal.connection.RealCall.getResponseWithInterceptorChain$okhttp(RealCall.java:201) at okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.java:517) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) at java.lang.Thread.run(Thread.java:923)

Haven’t seen this crash for some time now. Great Job 👍

Thanks @dave-r12. It turns out to be the case, somehow build was not pulling 3.9.0. I will provide feedback after testing with 3.9.0. Thank you once again.

Bad news, guys. I’ve just got this crash on okhttp v4.4.0 (on Android).

Fixed in OkHttp 3.12.

java.util.NoSuchElementException at okhttp3.internal.connection.RouteSelector.next(RouteSelector.java:78) at okhttp3.internal.connection.StreamAllocation.findConnection(StreamAllocation.java:171) at okhttp3.internal.connection.StreamAllocation.findHealthyConnection(StreamAllocation.java:121) at okhttp3.internal.connection.StreamAllocation.newStream(StreamAllocation.java:100) at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:42) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67) at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67) at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92) at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:120) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67) at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:185) at okhttp3.RealCall$AsyncCall.execute(RealCall.java:135) at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569) at java.lang.Thread.run(Thread.java:856)

@swankjesse I think because I save it to the array and clear ( cancelAll () ) the whole array when I exit the screen.


public class StreetViewWebService extends WebServiceBase {

    private int size = 0;
    private int threshold = 0;

    private static final String TAG = StreetViewWebService.class.getSimpleName();

    OkHttpClient client;

    private Context context;

    HashMap<Integer, retrofit2.Call<ResponseBody>> calls;

    StreetViewInterface mService;

    public StreetViewWebService(Context context) {
        client = new OkHttpClient();
        size = context.getResources().getInteger(R.integer.probe_default_size);
        threshold = context.getResources().getInteger(R.integer.availability_threshold);
        this.context = context;
        calls = new HashMap<>();
        mService = new Retrofit.Builder()
                .baseUrl(getApplicationWebserviceURL())
                .build()
                .create(StreetViewInterface.class);
    }

    public synchronized void probe(final Integer AdId, final double lat, final double lon, final OnStreetViewStatusListener listener) {
        if (AdId == null) return;
        String path = context.getResources().getString(R.string.probe_path, size, lat, lon);
        retrofit2.Call<ResponseBody> call =
                mService.streetView(path);
        calls.put(AdId, call);
        call.enqueue(new retrofit2.Callback<ResponseBody>() {
            @Override
            public void onResponse(retrofit2.Call<ResponseBody> call, Response<ResponseBody> response) {
                if (listener != null) {
                    if (response.body() != null) {
                        listener.onStreetViewStatus(response.body().contentLength() > threshold ? Status.AVAILABLE : Status.UNAVAILABLE);
                    } else {
                        listener.onStreetViewStatus(Status.UNKNOWN);
                    }
                }
                cancelStreetView(AdId);
                Log.d(TAG,"onResponse");
            }

            @Override
            public void onFailure(retrofit2.Call<ResponseBody> call, Throwable t) {
                if (listener != null) {
                    listener.onStreetViewStatus(Status.UNKNOWN);
                }
                cancelStreetView(AdId);
                Log.d(TAG,"onFailure");
            }
        });
    }

    @IntDef({Status.UNKNOWN, Status.AVAILABLE, Status.UNAVAILABLE})
    @Retention(RetentionPolicy.SOURCE)
    public @interface Status {
        int UNKNOWN = 0;
        int AVAILABLE = 1;
        int UNAVAILABLE = 2;
    }

    public interface OnStreetViewStatusListener {
        void onStreetViewStatus(@Status int status);
    }

    public synchronized void cancelStreetView(Integer AdId) {
        if (AdId == null) return;
        if (calls.containsKey(AdId)) {
            if (!calls.get(AdId).isCanceled()) {
                calls.get(AdId).cancel();
                calls.remove(AdId);
            }
        }
    }

public void cancelAll() {
        if (calls != null) {
            calls.clear();
        }
    }
}

If you could help to reproduce it, that’s the first step.