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

UI Thread blocking issue in Retrofit 2.11 and Android 15 #4307

Open
InputOutputZ opened this issue Feb 28, 2025 · 1 comment
Open

UI Thread blocking issue in Retrofit 2.11 and Android 15 #4307

InputOutputZ opened this issue Feb 28, 2025 · 1 comment

Comments

@InputOutputZ
Copy link

InputOutputZ commented Feb 28, 2025

Hi there,

I work on an app, and had this emerging issue with retrofit blocking the UI Thread in Android 15 while when I test the same app installed on Android 12 using same recent retrofit 2.11 and okhttp 4.12 releases, I can't reproduce the issue.

The blocking takes place when the responding server, returns 503 unavailable service after request time out. It can be reproduced if you run proxy on port 443, which redirects requests to web server running on another port, and if you stop the web server, the proxy will try to connect to it and wait for few seconds until it times out, and Android has 16ms time limit for any process to run and render in UI Thread before ui thread blocking jarring can be observed degrading the user experience, and the proxy waits for response and takes more than several seconds and here where retrofit service running through enqueue causes the jarring.

This is on Android 15
https://github.com/user-attachments/assets/7eeeec43-b157-4387-9759-ebc03b9e24e2

This is on Android 12
https://github.com/user-attachments/assets/aeaaf8d8-eb3d-40b4-b636-1a82df5ee764

I looked at every release changes from 12 to 15 and there is nothing related to the way I enqueue retrofit call. I tried to enclose enqueue and execute calls inside another Thread and it didn't make difference. It looks like at some point retrofit exits the Thread or makes early request to establish connection in the main thread, and as result of 503 unavailable service which takes several seconds to respond exceeding 16ms limit, it gets stuck in and blocks the UI Thread.

Please mind me for reporting this, as I'm not 100% sure if its a bug, it could be something wrong in my implementation causing the issue to take place when I execute e.g. following code inside fragment yet wonder why this doesnt happen in Android 12:-

    animationHandler = new Handler(Looper.getMainLooper());
    animationHandler.post(new Runnable() {
        showIndeterminateProgressBar();
    });
    call = service.notifications();
    call.enqueue(new Callback<Results>() {
        
        @Override
        public void onResponse(@NonNull Call<Results> call, @NonNull Response<Results> response) {


        }

        @Override
        public void onFailure(Call<Results> call, Throwable t) {
            animationHandler.post(new Runnable() {
                hideIndeterminateProgressBar();
            });
        }
        
    });

I tried running fragmentView.setLayerType(View.LAYER_TYPE_HARDWARE, null); yet it didnt make difference.

Any suggestion would be appreciated, and if you can confirm this is a bug, please let me know on how I. can assisst if I can any further to get it fixed.

With thanks.

Zakaria.

Source
https://developer.android.com/studio/profile/jank-detection

@InputOutputZ
Copy link
Author

Update, I just found this, possible change related to retrofit or okhttp in case any uses jobscheduler.

Android 14
https://developer.android.com/about/versions/14/behavior-changes-14#jobscheduler-reinforces-behavior

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

1 participant