Glide: StateVerifier throw if needed 4.4.0

Created on 6 Dec 2017  路  15Comments  路  Source: bumptech/glide

Stack:

Fatal Exception: java.lang.IllegalStateException: Already released
       at com.bumptech.glide.util.pool.StateVerifier$DefaultStateVerifier.throwIfRecycled(StateVerifier.java:44)
       at com.bumptech.glide.request.SingleRequest.onResourceReady(SingleRequest.java:518)
       at com.bumptech.glide.load.engine.EngineJob.handleResultOnMainThread(EngineJob.java:217)
       at com.bumptech.glide.load.engine.EngineJob$MainThreadCallback.handleMessage(EngineJob.java:322)
       at android.os.Handler.dispatchMessage(Handler.java:98)
       at android.os.Looper.loop(Looper.java:136)
       at android.app.ActivityThread.main(ActivityThread.java:5584)
       at java.lang.reflect.Method.invokeNative(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:515)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
       at dalvik.system.NativeStart.main(NativeStart.java)

Fabric

bug repro-needed

Most helpful comment

@sjudd Seems to be fixed in 4.5.0

All 15 comments

Let me know if you find a way to reproduce this, or attach a test with a failing test case: http://bumptech.github.io/glide/tut/failing-test-cases.html

We managed to reproduce the error with that additional information:

12-11 13:18:36.540 9220-9220/? W/Bitmap: Called hasAlpha() on a recycle()'d bitmap! This is undefined behavior!
12-11 13:18:36.540 9220-9220/? W/Bitmap: Called hasAlpha() on a recycle()'d bitmap! This is undefined behavior!
12-11 13:18:36.540 9220-9220/? W/Bitmap: Called hasAlpha() on a recycle()'d bitmap! This is undefined behavior!
12-11 13:18:36.719 1429-8786/? W/MdnsClient: Socket thread is null
12-11 13:18:36.823 9220-9220/? W/Glide: Load failed for https://www.app.com/content/portraits-thumb/072/0723544.jpg with size [216x216]
                                        class com.bumptech.glide.load.engine.GlideException: Failed to load resource
                                          Cause (1 of 1): class com.bumptech.glide.load.engine.GlideException: Fetching data failed, class java.io.InputStream, REMOTE
                                            Cause (1 of 1): class com.bumptech.glide.load.engine.GlideException: Fetch failed
                                              Cause (1 of 1): class java.net.UnknownHostException: Unable to resolve host "www.app.com": No address associated with hostname
12-11 13:18:36.823 9220-9220/? I/Glide: Root cause (1 of 1)
12-11 13:18:37.236 9220-9220/? E/AndroidRuntime: FATAL EXCEPTION: main
                                                 Process: com.app, PID: 9220
                                                 java.lang.IllegalStateException: Already released
                                                     at com.bumptech.glide.g.a.b$a.b(StateVerifier.java:44)
                                                     at com.bumptech.glide.request.SingleRequest.a(SingleRequest.java:518)
                                                     at com.bumptech.glide.load.engine.j.c(EngineJob.java:217)
                                                     at com.bumptech.glide.load.engine.j$b.handleMessage(EngineJob.java:322)
                                                     at android.os.Handler.dispatchMessage(Handler.java:98)
                                                     at android.os.Looper.loop(Looper.java:154)
                                                     at android.app.ActivityThread.main(ActivityThread.java:6077)
                                                     at java.lang.reflect.Method.invoke(Native Method)
                                                     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
                                                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)

The problem appears when going offline while glide is loading a remote resource

Can you provide the set of steps that you used to reproduce the error? What load line are you using? How often does it reproduce?

Happened 255 times - Fabric

It happens various place in the code
A load example where we know it can crash:

Glide.with(getContext())
                    .load(account.getProfilePictureThumbUrl())
                    .apply(new RequestOptions()
                            .fitCenter()
                            .centerCrop())
                    .apply(RequestOptions.bitmapTransform(new RoundedCorners(getContext().getResources().getDimensionPixelSize(R.dimen.corner_radius))))
                    .error(getOfflineRequest(R.drawable.as_shared_default_picture_offline, RequestOptions.bitmapTransform(new RoundedCorners(getContext().getResources().getDimensionPixelSize(R.dimen.corner_radius)))))
                    .listener(new RequestListener<Drawable>() {
                        @Override
                        public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
                            if (picture == null || progress == null) return false;
                            picture.setVisibility(View.VISIBLE);
                            progress.setVisibility(View.INVISIBLE);
                            if (runnableSuccess != null) { runnableSuccess.run(); }
                            return false;
                        }

                        @Override
                        public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
                            if (picture == null || progress == null) return false;
                            picture.setVisibility(View.VISIBLE);
                            progress.setVisibility(View.INVISIBLE);
                            if (runnableSuccess != null) { runnableSuccess.run(); }
                            return false;
                        }
                    })
                    .into(picture);

To reproduce:
Start many remote loads with Glide and go offline before Glide is done loading

Do you have an AppGlideModule or are you otherwise registering any components? Can you provide the implementation if you are?

GlideModule:

@com.bumptech.glide.annotation.GlideModule
public class GlideModule extends AppGlideModule {
    @Override
    public void applyOptions(Context context, GlideBuilder builder) {
        builder.setIsActiveResourceRetentionAllowed(false);
    }
}

Usage:

ublic class DefaultImageLoader implements ImageLoader {

    @Override
    public void loadImage(String path, ImageView imageView, ImageType imageType) {
        GlideApp.with(imageView.getContext())
                .load(path)
                .apply(RequestOptions.centerCropTransform()
                        .placeholder(imageType == ImageType.FOLDER ? R.drawable.folder_placeholder : R.drawable.image_placeholder)
                        .error(imageType == ImageType.FOLDER ? R.drawable.folder_placeholder : R.drawable.image_placeholder)
                )
                .into(imageView);
    }
}

GlideApp is only used for managing local images and therefor it should not be related to this issue

This bug seems to be related to network conditions. We have been able to reproduce it while loading images in a viewpager and go offline while swiping back and fourth.

Any progress?

This is our number one bug

Maybe if you're able to attach a sample app where this is reproducible? I don't see anything obviously wrong with your code.

Also are you using any networking libraries? Or just Glide's default?

Internal bug is b/70869251

We are not able to reproduce on every devices.
The one that can be crashed manually is an LG G3.
Glide's default, we use Retrofit and okHTTP for RestAPI calls only.

@sjudd Seems to be fixed in 4.5.0

Great then I think this was a duplicate of #2767.

Still occurs in Glide 4.6.1

Only on devices below Android 5. I can reproduce in this way:
I have a ViewPager with Fragments which contain lists with images. When I start a fling on one Fragment and then switch to another Fragment the crash happens.

Please let me know if this is a new bug for you. If yes, I provide you a new issue with detailed information

The stack changed a little bit:

java.lang.IllegalStateException: Already released
at com.bumptech.glide.util.pool.StateVerifier$DefaultStateVerifier.throwIfRecycled(StateVerifier.java:46)
at com.bumptech.glide.load.engine.EngineJob.addCallback(EngineJob.java:125)
at com.bumptech.glide.load.engine.Engine.load(Engine.java:193)
at com.bumptech.glide.request.SingleRequest.onSizeReady(SingleRequest.java:451)
at com.bumptech.glide.request.target.ViewTarget$SizeDeterminer.getSize(ViewTarget.java:383)
at com.bumptech.glide.request.target.ViewTarget.getSize(ViewTarget.java:215)
at com.bumptech.glide.request.SingleRequest.begin(SingleRequest.java:264)
at com.bumptech.glide.manager.RequestTracker.runRequest(RequestTracker.java:42)
at com.bumptech.glide.RequestManager.track(RequestManager.java:634)
at com.bumptech.glide.RequestBuilder.into(RequestBuilder.java:618)
at com.bumptech.glide.RequestBuilder.into(RequestBuilder.java:583)
at com.bumptech.glide.RequestBuilder.into(RequestBuilder.java:576)

@camino2007 please do file a new issue. If you're using a custom Target please include that as well.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

billy2271 picture billy2271  路  3Comments

FooBarBacon picture FooBarBacon  路  3Comments

StefMa picture StefMa  路  3Comments

Tryking picture Tryking  路  3Comments

AndroidJohnsonWang picture AndroidJohnsonWang  路  3Comments