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 Interceptors inactive and Picasso takes 25 - 30 seconds to render an image #2086

Open
jbrinnand opened this issue May 24, 2019 · 0 comments

Comments

@jbrinnand
Copy link

jbrinnand commented May 24, 2019

       OkHttpClient client = new OkHttpClient().newBuilder()
                .readTimeout(500, TimeUnit.MILLISECONDS)
                .connectTimeout(325, TimeUnit.MILLISECONDS)
                .addInterceptor(new Interceptor() {
                    @Override
                    public okhttp3.Response intercept(Interceptor.Chain chain) throws IOException {
                        Timber.d("In the interceptor: ");
                        Request request = chain.request();
                        okhttp3.Response response = null;
                        try {
                            response = chain.proceed(request);
                        } catch (IOException e) {
                            Timber.d("ERROR: %s", e.getLocalizedMessage());
                        }

                        int count = 0;
                        int maxLimit = 3;
                        while (response == null || !response.isSuccessful() && count < maxLimit) {
                            count++;
                            // retry the request
                            response = chain.proceed(request);
                            Timber.d("Retrying the request: %s", count);
                        }
                        return response;
                    }
                }).build();

        Picasso picasso = new Picasso.Builder(getContext())
                .downloader(new OkHttp3Downloader(client)).build();
        picasso.get().load(imagePath).placeholder(R.drawable.whitespace)
                .tag(target).into(target);

Now when the network is down, it takes 25 - 30 seconds for Picasso to render an image. However, if the okHttp3 client is run in standalone mode - outside picasso, the interceptor is called every time and the behavior of the okHttp3 client is consistent and can be rationalized. However, once this client is placed into Picasso, the interceptor is not called - it's as if it is not being used. The imagePath does contain the "scheme" - http in this case, so I am not sure what is wrong with this code or what is being missed but it is very consistent: whenever network integrity is in question, it takes 25 - 30 seconds before Picasso gets the image from cache or disk and renders it.

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