stephanenicolas / robospice

Repo of the Open Source Android library : RoboSpice. RoboSpice is a modular android library that makes writing asynchronous long running tasks easy. It is specialized in network requests, supports caching and offers REST requests out-of-the box using extension modules.
Apache License 2.0
2.94k stars 545 forks source link

removeDataFromCache doesn't work anymore on RoboSpice 1.4.5 #116

Closed mhausherr closed 11 years ago

mhausherr commented 11 years ago

My StackTrace

java.util.concurrent.RejectedExecutionException: Task com.octo.android.robospice.SpiceManager$16@42624cc8 rejected from java.util.concurrent.ThreadPoolExecutor@419d91c8[Terminated, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 0] 1 at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:1967) 2 at java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:782) 3 at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1303) 4 at java.util.concurrent.Executors$DelegatedExecutorService.execute(Executors.java:600) 5 at com.octo.android.robospice.SpiceManager.removeAllDataFromCache(SpiceManager.java:944)

stephanenicolas commented 11 years ago

Did this exception have a cause that you didn't post ?

1.4.5 is actually a snapshot. We outta work on it before releasing it.

A more complete stack would definitely help.

S. Le 8 juin 2013 13:01, "Mathieu Hausherr" notifications@github.com a écrit :

My StackTrace

java.util.concurrent.RejectedExecutionException: Task com.octo.android.robospice.SpiceManager$16@42624cc8 rejected from java.util.concurrent.ThreadPoolExecutor@419d91chttps://github.com/java.util.concurrent.ThreadPoolExecutor/robospice/commit/419d91c8[Terminated, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 0] 1 at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:1967) 2 at java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:782) 3 at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1303) 4 at java.util.concurrent.Executors$DelegatedExecutorService.execute(Executors.java:600) 5 at com.octo.android.robospice.SpiceManager.removeAllDataFromCache(SpiceManager.java:944)

— Reply to this email directly or view it on GitHubhttps://github.com/octo-online/robospice/issues/116 .

stephanenicolas commented 11 years ago

There used to be a bug in SNAPSHOT release when multiple threads would create the same cache folder simultaneously. It's been fixed.

DanielNovak commented 11 years ago

getSpiceManager().removeAllDataFromCache() doesn't work even in the final release. This bug happens on 2.3 but not on 4.0+ Android. I think this is pretty serious because if you have an application where the user can log out and a different user will log in, then he will see the cached data from the previous user.

awbranch commented 11 years ago

Having the same problem with 1.4.5. Downgraded to 1.4.4 to fix. I have a button that allows you to manually clear the cache. Here's the 1.4.5 stack trace:

java.util.concurrent.RejectedExecutionException: Task com.octo.android.robospice.SpiceManager$9@429f7ca0 rejected from java.util.concurrent.ThreadPoolExecutor@4294bc48[Terminated, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 2] at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:1967) at java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:782) at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1303) at com.octo.android.robospice.SpiceManager.cancelAllRequests(SpiceManager.java:773) at com.winewize.merlot.SettingsActivity.clearCache(SettingsActivity.java:247) at com.winewize.merlot.SettingsActivity.access$1(SettingsActivity.java:245) at com.winewize.merlot.SettingsActivity$3$1.onClick(SettingsActivity.java:121) at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:166) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:4745) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) at dalvik.system.NativeStart.main(Native Method)

stephanenicolas commented 11 years ago

Does the pbm happen on Android 2.3 as Daniel reported it ? Or on any version of android ?

Stéphane

2013/7/7 Andrew Branch notifications@github.com

Having the same problem with 1.4.5. Downgraded to 1.4.4 to fix. I have a button that allows you to manually clear the cache. Here's the 1.4.5 stack trace:

java.util.concurrent.RejectedExecutionException: Task com.octo.android.robospice.SpiceManager$9@429f7ca0 rejected from java.util.concurrent.ThreadPoolExecutor@4294bc4https://github.com/java.util.concurrent.ThreadPoolExecutor/robospice/commit/4294bc48[Terminated, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 2] at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:1967) at java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:782) at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1303) at com.octo.android.robospice.SpiceManager.cancelAllRequests(SpiceManager.java:773) at com.winewize.merlot.SettingsActivity.clearCache(SettingsActivity.java:247) at com.winewize.merlot.SettingsActivity.access$1(SettingsActivity.java:245) at com.winewize.merlot.SettingsActivity$3$1.onClick(SettingsActivity.java:121) at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:166) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:4745) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) at dalvik.system.NativeStart.main(Native Method)

— Reply to this email directly or view it on GitHubhttps://github.com/octo-online/robospice/issues/116#issuecomment-20572966 .

Stéphane NICOLAS, OCTO Technology Développeur & Consultant Android / Java .......................................................... 50, Avenue des Champs-Elysées 75008 Paris +33 (0)6.26.32.34.09 www.octo.com - blog.octo.com www.usievents.com ...........................................................

awbranch commented 11 years ago

I saw it on 4.1.2. Didn't test beyond that.

Andrew

On Mon, Jul 8, 2013 at 1:38 AM, stephanenicolas notifications@github.comwrote:

Does the pbm happen on Android 2.3 as Daniel reported it ? Or on any version of android ?

Stéphane

2013/7/7 Andrew Branch notifications@github.com

Having the same problem with 1.4.5. Downgraded to 1.4.4 to fix. I have a button that allows you to manually clear the cache. Here's the 1.4.5 stack trace:

java.util.concurrent.RejectedExecutionException: Task com.octo.android.robospice.SpiceManager$9@429f7ca0 rejected from java.util.concurrent.ThreadPoolExecutor@4294bc4< https://github.com/java.util.concurrent.ThreadPoolExecutor/robospice/commit/4294bc48>[Terminated,

pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 2] at

java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:1967)

at

java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:782) at

java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1303)

at

com.octo.android.robospice.SpiceManager.cancelAllRequests(SpiceManager.java:773)

at

com.winewize.merlot.SettingsActivity.clearCache(SettingsActivity.java:247) at com.winewize.merlot.SettingsActivity.access$1(SettingsActivity.java:245) at

com.winewize.merlot.SettingsActivity$3$1.onClick(SettingsActivity.java:121) at

com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:166)

at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:4745) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at

com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)

at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) at dalvik.system.NativeStart.main(Native Method)

— Reply to this email directly or view it on GitHub< https://github.com/octo-online/robospice/issues/116#issuecomment-20572966>

.

Stéphane NICOLAS, OCTO Technology Développeur & Consultant Android / Java .......................................................... 50, Avenue des Champs-Elysées 75008 Paris +33 (0)6.26.32.34.09 www.octo.com - blog.octo.com www.usievents.com ...........................................................

— Reply to this email directly or view it on GitHubhttps://github.com/octo-online/robospice/issues/116#issuecomment-20586488 .

stephanenicolas commented 11 years ago

We can't reproduce the bug in 1.4.5 and 1.4.6-SNAPSHOT. Unless someone can provide more information, I will close the bug within a few days.

S.

2013/7/8 Andrew Branch notifications@github.com

I saw it on 4.1.2. Didn't test beyond that.

Andrew

On Mon, Jul 8, 2013 at 1:38 AM, stephanenicolas notifications@github.comwrote:

Does the pbm happen on Android 2.3 as Daniel reported it ? Or on any version of android ?

Stéphane

2013/7/7 Andrew Branch notifications@github.com

Having the same problem with 1.4.5. Downgraded to 1.4.4 to fix. I have a button that allows you to manually clear the cache. Here's the 1.4.5 stack trace:

java.util.concurrent.RejectedExecutionException: Task com.octo.android.robospice.SpiceManager$9@429f7ca0 rejected from java.util.concurrent.ThreadPoolExecutor@4294bc4<

https://github.com/java.util.concurrent.ThreadPoolExecutor/robospice/commit/4294bc48>[Terminated,

pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 2] at

java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:1967)

at

java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:782)

at

java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1303)

at

com.octo.android.robospice.SpiceManager.cancelAllRequests(SpiceManager.java:773)

at

com.winewize.merlot.SettingsActivity.clearCache(SettingsActivity.java:247)

at com.winewize.merlot.SettingsActivity.access$1(SettingsActivity.java:245) at

com.winewize.merlot.SettingsActivity$3$1.onClick(SettingsActivity.java:121)

at

com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:166)

at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:4745) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at

com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)

at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) at dalvik.system.NativeStart.main(Native Method)

— Reply to this email directly or view it on GitHub<

https://github.com/octo-online/robospice/issues/116#issuecomment-20572966>

.

Stéphane NICOLAS, OCTO Technology Développeur & Consultant Android / Java .......................................................... 50, Avenue des Champs-Elysées 75008 Paris +33 (0)6.26.32.34.09 www.octo.com - blog.octo.com www.usievents.com ...........................................................

— Reply to this email directly or view it on GitHub< https://github.com/octo-online/robospice/issues/116#issuecomment-20586488>

.

— Reply to this email directly or view it on GitHubhttps://github.com/octo-online/robospice/issues/116#issuecomment-20600365 .

Stéphane NICOLAS, OCTO Technology Développeur & Consultant Android / Java .......................................................... 50, Avenue des Champs-Elysées 75008 Paris +33 (0)6.26.32.34.09 www.octo.com - blog.octo.com www.usievents.com ...........................................................

bishiboosh commented 11 years ago

I reproduce it, I call cancelAll to cancel loading, and got the exception too.

Here is a gist with the log and the stacktrace : https://gist.github.com/bishiboosh/6000690

stephanenicolas commented 11 years ago

The issue has been reported with more details here : https://github.com/octo-online/robospice/issues/128

It is solved in current snapshot. Release 1.4.6 is around the corner.

S.

2013/7/15 Valentin R. notifications@github.com

I reproduce it, I call cancelAll to cancel loading, and got the exception too.

Here is a gist with the log and the stacktrace : https://gist.github.com/bishiboosh/6000690

— Reply to this email directly or view it on GitHubhttps://github.com/octo-online/robospice/issues/116#issuecomment-20975787 .

Stéphane NICOLAS, OCTO Technology Développeur & Consultant Android / Java .......................................................... 50, Avenue des Champs-Elysées 75008 Paris +33 (0)6.26.32.34.09 www.octo.com - blog.octo.com www.usievents.com ...........................................................

mdumrauf commented 11 years ago

I tried 1.4.6 and still tackle with this issue. Anyone else having the same problem too?

stephanenicolas commented 11 years ago

Can you provide a sample ? Or better, a failing test..

2013/8/1 Matías Dumrauf notifications@github.com

I tried 1.4.6 and still tackle with this issue. Anyone else having the same problem too?

— Reply to this email directly or view it on GitHubhttps://github.com/octo-online/robospice/issues/116#issuecomment-21963368 .

Stéphane NICOLAS, OCTO Technology Développeur & Consultant Android / Java .......................................................... 50, Avenue des Champs-Elysées 75008 Paris +33 (0)6.26.32.34.09 www.octo.com - blog.octo.com www.usievents.com ...........................................................

mdumrauf commented 11 years ago

Don't have time to provide an automated failing test, but the way I checked it was:

1- Fetch data this way:

spiceManager.execute(new BigBinaryRequest(url, cacheFile), cacheFile.getName(), DurationInMillis.ALWAYS_RETURNED, requestListener);

2- Clear the cache:

@Override
    protected void onDestroy() {
        spiceManager.removeAllDataFromCache();
        super.onDestroy();
    }

I understand that removeAllDataFromCache() returns a Future that will be executed. But if a check the cache directory of the app, files are stil there.

stephanenicolas commented 11 years ago

Hi Matías,

thank you very much for this snippet. I will try to turn it into a sample and inspect RS behavior. Nevertheless, I see that you are using a BigBinaryRequest. Those requests need a cache file by their own and don't rely on RS cache mechanism. The file they use is not handled by RS cache manager and it can't delete it.

Can you confirm that removeDataFromCache works or breaks for other types of request or only fail for BigBinaryRequests ? For all other requests, it should work though.

The later scenario wouldn't be a bug, but more "a surprising detail" that it's not really possible to correct with actual RS design.

Stéphane

2013/8/12 Matías Dumrauf notifications@github.com

Don't have time to provide an automated failing test, but the way I checked it was:

1- Fetch data this way:

spiceManager.execute(new BigBinaryRequest(url, cacheFile), cacheFile.getName(), DurationInMillis.ALWAYS_RETURNED, requestListener);

2- Clear the cache:

@Override protected void onDestroy() { firebase = null; spiceManager.removeAllDataFromCache(); super.onDestroy(); }

I understand that *removeAllDataFromCache() returns a Future that will be executed. But if a check the cache directory of the app, files are stil there.

— Reply to this email directly or view it on GitHubhttps://github.com/octo-online/robospice/issues/116#issuecomment-22514498 .

Stéphane NICOLAS, OCTO Technology Développeur & Consultant Android / Java .......................................................... 50, Avenue des Champs-Elysées 75008 Paris +33 (0)6.26.32.34.09 www.octo.com - mobilite.octo.com blog.octo.com - www.usievents.com ...........................................................

mdumrauf commented 11 years ago

I will try it with another simple resource. I've already tried the image-caching example and it works.

Regarding BigBinaryRequest, I'm now ensuring that the cacheFile gets deleted onDestroy(). So I think it is, as you said, a rare behavior in RS. For the record, I'm now cleaning the cache directory manually with Apache Commons' FileUtils, so I can still use RS's cache feature. I create the file in the cache directory (context.getCacheDir()) and the implementation of onDestroy() looks like this:

    @Override
    protected void onDestroy() {
        clearCache();
        super.onDestroy();
    }

    private void clearCache() {
        spiceManager.removeAllDataFromCache();
        try {
            FileUtils.cleanDirectory(getCacheDir());
        } catch (IOException e) {
            Log.e(TAG, "Could not clean cache directory: " + e.getMessage());
        }
    }
stephanenicolas commented 11 years ago

Hi Mathias,

the situation is more clear now. I will add a note inside the BigBinaryRequest's Javadoc to let devs know that they have to handle the cache file erasure by themselves and that this cache file is not handled by RS caching mechanism in the "normal way".

Thx for clearing things out.

I, and others, are worried about this "exceptional behavior" in RS. But our actual design is that requests are cache agnostic, and this provides many advantages from a design point of view. Unfortunately the draw back is that it's not possible for requests to "get a reference" to a cache location via the cache manager, and if they handle a cache file of their own (like bigrequests) then the cache manager won't have any knowledge of it neither.

Things could be improved in some obvious ways (like injecting the cache manager inside a spicerequest, or hard coding some special behavior in RS for request that handle cache by themselves, but I don't see any of these solutions as fully satisfying from a software design point of view. But I am pretty sure there is a clean and neat way of implementing this in RS, I just hadn't time to fully think about it.

stephanenicolas commented 11 years ago

Doc updated in commit : d6ccebc088b00f175e900d471b17027056a333da

mdumrauf commented 11 years ago

Great. Hope this gets improved soon. I'll try to get more involved in the short term.