Skip to content
This repository has been archived by the owner on Jan 14, 2018. It is now read-only.

Deadlock while using service #203

Closed
bigfatbrowncat opened this issue Oct 19, 2013 · 5 comments
Closed

Deadlock while using service #203

bigfatbrowncat opened this issue Oct 19, 2013 · 5 comments
Assignees
Milestone

Comments

@bigfatbrowncat
Copy link

I have implemented a simple service based on RoboSpice's SpiceService class.

public class CachedSpiceService extends SpiceService {

    @Override
    public CacheManager createCacheManager(Application application) throws CacheCreationException {
        CacheManager cacheManager = new CacheManager();

        KinohodGsonFactory gsonFactory = KinohodGsonFactory.getInstance();

        // init
        InFileStringObjectPersister inFileStringObjectPersister = new InFileStringObjectPersister(application);
        InFileBitmapObjectPersister inFileBitmapObjectPersister = new InFileBitmapObjectPersister(application);
        ....
        <some other persisters there>
        ....
        return cacheManager;
    }

    @Override
    public int getThreadCount() {
        return 3;
    }
}

When I use it, the application freezes accidentally (possible a kind of a deadlock) with this log:

< Here my main activity reports onCreate event >
10-19 18:44:33.761: D//SpiceManager.java:203(26356): 18:44:33.766 main SpiceManager started.
< Here my main activity reports onStart event >
10-19 18:44:33.791: V//SpiceManager.java:1155(26356): 18:44:33.776 SpiceManagerThread 0 Binding to service.
10-19 18:44:33.791: V//SpiceManager.java:1161(26356): 18:44:33.797 SpiceManagerThread 0 Binding to service succeeded.
10-19 18:44:33.796: D//SpiceManager.java:1208(26356): 18:44:33.799 SpiceManagerThread 0 Waiting for service to be bound.
10-19 18:44:33.861: D//SpiceManager.java:1208(26356): 18:44:33.864 Thread-974 Waiting for service to be bound.

So the service is never being bound. The problem occurs in about 50% times the application get launched.
@stephanenicolas
Copy link
Owner

Hi llya,

how do you start and stop your service ? Are you sure it is related to using a cachemanager ? Which version of RS do you use. Brief, we need more details.

@bigfatbrowncat
Copy link
Author

I use version 1.4.8.

No, there is nothing about CacheManager.

I found the root cause of this problem, but I had no time to analyze your code well. Briefly, my activity calls spiceManager.start(this) in its onStart() and after that (after some other preparations) it starts executing requests with spiceManager.execute().

As I found, the problem occurs if I call spiceManager.execute() before the service is actually bound and doesn't occur if it goes after.

Strictly speaking if SpiceManager connects to the service before anyone asks it for executing a request, everything's ok.

I made a dirty workaround - added Thread.sleep(2000) in my onStart method after spiceManager.start(this), so the service has more time. The bug disappeared.

Now I took all your sources into my project and hacked SpiceServiceConnection class that now it sends me an event after connection. This workaround works well.

If it's not just a stupid deadlock which could be fixed easily (I'm not sure how it should work), maybe you could create such an event (something like onBound)...

Please, tell me when this is solved thus I could update my version of RoboSpice and remove my hack.

@stephanenicolas
Copy link
Owner

Hi @bigfatbrowncat , this will take some time. Next week I should find some time to dig into this issue. I will first setup a test and if it fails, I will try to resolve it and submit a new snapshot that you can try.

This issue is close to another that I am aware of since a few days. I will detail it here as a reminder.

Fire and forget requests don't work.

If you execute a request and finish the activity right after execute, the request is not launched.

@ghost ghost assigned stephanenicolas Oct 23, 2013
@rpk98c
Copy link

rpk98c commented Nov 4, 2013

Hi

@stephanenicolas did you manage to find any time for this? I'm seeing very similar issues in the wild. With ANR's being reported with the threads deadlocked on waitForServiceToBeBound() call.

FYI I have an Activity that calls SpiceManage.onStart(), immediately followed by a call to getAllCacheKeys(). execute is also called shortly after.

Thanks,

Ryan

@stephanenicolas
Copy link
Owner

Hi @bigfatbrowncat and @rpk98c , not sure if this all still applies. Sorry for the delay, I took some time off.

Can one of you provide a working (or better, a bugging) example somewhere on git ?

Also, @rpk98c , getAllCacheKeys will block, and should not be called from the UI Thread.

Meanwhile I close that thread.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants