Skip to content
This repository has been archived by the owner on May 26, 2022. It is now read-only.

OutOfMemoryError #31

Closed
G00fY2 opened this issue Nov 22, 2017 · 10 comments
Closed

OutOfMemoryError #31

G00fY2 opened this issue Nov 22, 2017 · 10 comments

Comments

@G00fY2
Copy link

G00fY2 commented Nov 22, 2017

Like I wrote yesterday, I updated RxDNSSD to 0.9.3 (mainly because I hoped the following issue may been fixed) but I still get this error after a while and my app freezes. Normally this error appears when I do nothing within the app. Seems like it occurs in some background progress.

Maybe you have an idea?

11-22 13:53:21.117  W/art: Throwing OutOfMemoryError "pthread_create (1040KB stack) failed: Out of memory"
11-22 13:53:21.118  W/System.err: java.lang.OutOfMemoryError: pthread_create (1040KB stack) failed: Out of memory
11-22 13:53:21.118  W/System.err:     at java.lang.Thread.nativeCreate(Native Method)
11-22 13:53:21.119  W/System.err:     at java.lang.Thread.start(Thread.java:1078)
11-22 13:53:21.119  W/System.err:     at com.github.druk.dnssd.AppleQuery.<init>(InternalDNSSD.java:846)
11-22 13:53:21.119  W/System.err:     at com.github.druk.dnssd.AppleDNSSD._queryRecord(InternalDNSSD.java:593)
11-22 13:53:21.119  W/System.err:     at com.github.druk.dnssd.InternalDNSSD.queryRecord(InternalDNSSD.java:323)
11-22 13:53:21.119  W/System.err:     at com.github.druk.dnssd.DNSSD.queryRecord(DNSSD.java:411)
11-22 13:53:21.119  W/System.err:     at com.github.druk.rxdnssd.RxDnssdCommon$3$1$2.getService(RxDnssdCommon.java:113)
11-22 13:53:21.119  W/System.err:     at com.github.druk.rxdnssd.RxDnssdCommon$DNSSDServiceAction.call(RxDnssdCommon.java:214)
11-22 13:53:21.119  W/System.err:     at com.github.druk.rxdnssd.RxDnssdCommon$DNSSDServiceAction.call(RxDnssdCommon.java:201)
11-22 13:53:21.119  W/System.err:     at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
11-22 13:53:21.119  W/System.err:     at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
11-22 13:53:21.119  W/System.err:     at rx.Observable.unsafeSubscribe(Observable.java:10256)
11-22 13:53:21.119  W/System.err:     at rx.internal.operators.OperatorMerge$MergeSubscriber.onNext(OperatorMerge.java:248)
11-22 13:53:21.119  W/System.err:     at rx.internal.operators.OperatorMerge$MergeSubscriber.onNext(OperatorMerge.java:148)
11-22 13:53:21.119  W/System.err:     at rx.internal.operators.OnSubscribeFromArray$FromArrayProducer.fastPath(OnSubscribeFromArray.java:76)
11-22 13:53:21.119  W/System.err:     at rx.internal.operators.OnSubscribeFromArray$FromArrayProducer.request(OnSubscribeFromArray.java:58)
11-22 13:53:21.119  W/System.err:     at rx.Subscriber.setProducer(Subscriber.java:211)
11-22 13:53:21.119  W/System.err:     at rx.internal.operators.OnSubscribeFromArray.call(OnSubscribeFromArray.java:32)
11-22 13:53:21.119  W/System.err:     at rx.internal.operators.OnSubscribeFromArray.call(OnSubscribeFromArray.java:24)
11-22 13:53:21.119  W/System.err:     at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
11-22 13:53:21.119  W/System.err:     at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
11-22 13:53:21.119  W/System.err:     at rx.Observable.unsafeSubscribe(Observable.java:10256)
11-22 13:53:21.119  W/System.err:     at rx.internal.operators.OperatorMerge$MergeSubscriber.onNext(OperatorMerge.java:248)
11-22 13:53:21.119  W/System.err:     at rx.internal.operators.OperatorMerge$MergeSubscriber.onNext(OperatorMerge.java:148)
11-22 13:53:21.119  W/System.err:     at rx.internal.operators.OnSubscribeMap$MapSubscriber.onNext(OnSubscribeMap.java:77)
11-22 13:53:21.119  W/System.err:     at rx.internal.operators.OperatorMerge$MergeSubscriber.emitScalar(OperatorMerge.java:395)
11-22 13:53:21.119  W/System.err:     at rx.internal.operators.OperatorMerge$MergeSubscriber.tryEmit(OperatorMerge.java:355)
11-22 13:53:21.119  W/System.err:     at rx.internal.operators.OperatorMerge$InnerSubscriber.onNext(OperatorMerge.java:846)
11-22 13:53:21.119  W/System.err:     at rx.observers.Subscribers$5.onNext(Subscribers.java:235)
11-22 13:53:21.119  W/System.err:     at com.github.druk.rxdnssd.RxResolveListener.serviceResolved(RxResolveListener.java:40)
11-22 13:53:21.119  W/System.err:     at com.github.druk.dnssd.DNSSD$2$1.run(DNSSD.java:232)
11-22 13:53:21.119  W/System.err:     at android.os.Handler.handleCallback(Handler.java:743)
11-22 13:53:21.119  W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:95)
11-22 13:53:21.119  W/System.err:     at android.os.Looper.loop(Looper.java:150)
11-22 13:53:21.119  W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:5659)
11-22 13:53:21.119  W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
11-22 13:53:21.119  W/System.err:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:822)
11-22 13:53:21.119  W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:712)```
@andriydruk
Copy link
Owner

andriydruk commented Nov 22, 2017

Could you provide sample code?
Do you have the same issue with "MainActivity.java" from my sample?

@G00fY2
Copy link
Author

G00fY2 commented Nov 22, 2017

Wasn't able to reproduce it in your sample project so far. But maybe I have not tried long enough, because the error appears only after a few minutes.

Can tell more tomorrow and may add some sample code.
Thanks for responding so fast! 👍

@G00fY2
Copy link
Author

G00fY2 commented Nov 25, 2017

Hi Andriy,
I'm using the DNSSDBindable version and on some devices I get this error pretty frequently. I changed your example app inside the project to use DNSSDBindable too, but I could not reproduce it.

But there are some other differences in my app. I use your library inside a singleton controller class which gets provided by dagger. I also use a PublishSubject from RxJava2 to forward the bonjourService results to RxJava2 chain. Doublechecked everything and can't find a leak or something which could cause the OutOfMemoryError.
Maybe I can somehow reproduce it in your sample app.

Btw: Is there a reason why you undeprecated the embedded version? I tried it but it takes more time to find devices after start browsing.

PS: Any news on #30? :)

@andriydruk
Copy link
Owner

It looks like your Rx chain has a lot uncompleted operation: hundreds or thousands. In your case you should always has only 1 long running browse operation and few temporary resolve and query
Try to make additional logging and understand what exactly operations are leaked.
You may need to compile rxdnssd from source code for that (no NDK needed).

You should definitely use DNSSDBindable, embedded version is only for old devices before 4.1 or some buggy Samsung with (4.4.2) and I'm not sure should I support this in 2017.

Also your bug looks like one that not depends on embedded or bindable realization of DNSSD

#30 - fixed

@G00fY2
Copy link
Author

G00fY2 commented Nov 25, 2017

Thanks!! I'm also starting to believe the issue is not caused by anything from your implementation. Will see if I can dive in some deeper by logging the running operations.

@namannik
Copy link

Hello. I'm seeing this occasionally, too. The stack trace is nearly identical to the one at the top of this thread. When this crash occurs, there are over 1000 threads with the same stack trace:

at com.github.druk.dnssd.AppleService.BlockForData(InternalDNSSD.java)
at com.github.druk.dnssd.AppleService.run(InternalDNSSD.java:690)
at java.lang.Thread.run(Thread.java:818)

Here are the crash details: http://crashes.to/s/4411a5e5655

Here's my code where I'm setting up RxDNSSD:

private void startSourceDiscovery() {

    if (rxDnssd == null)
        rxDnssd = new RxDnssdBindable(this);

    rxDnssd.browse(HEAR_TV_SERVICE_TYPE, "local.")
            .compose(rxDnssd.resolve())
            .compose(rxDnssd.queryRecords())
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(new Action1<BonjourService>() {
                @Override
                public void call(BonjourService bonjourService) {
                    if (!bonjourService.isLost()) {
                        serviceResolved(bonjourService);
                    } else {
                        serviceRemoved(bonjourService);
                    }
                }
            }, new Action1<Throwable>() {
                @Override
                public void call(Throwable throwable) {
                    Log.e("hearTVservice", "DNSSD Error: ", throwable);
                }
            });
}

private void stopSourceDiscovery() {
    rxDnssd = null;
}

public void refreshSourceList() {
    stopSourceDiscovery();
    sourceListClear();
    startSourceDiscovery();
}

I'm wondering if I shouldn't be setting rxDnssd to null and then reinitializing it when performing a refresh. Any thoughts on why this might be happening?

@andriydruk
Copy link
Owner

andriydruk commented Dec 13, 2017

Hi @namannik
Do you use latest version 0.9.5?

I'm wondering if I shouldn't be setting rxDnssd to null and then reinitializing it when performing a refresh. Any thoughts on why this might be happening?

No, it's not necessary

@namannik
Copy link

Thanks. I've been using 0.9.1. I'll try to 0.9.5 to see if this resolves the issue.

Side note: As recommended by @G00fY2 here, in order to upgrade from 0.9.1 to 0.9.5, I had to change my dependencies to:

implementation 'io.reactivex:rxjava:1.3.4'
implementation 'io.reactivex:rxandroid:1.2.1'
implementation 'com.github.andriydruk:dnssd:0.9.5'
api 'com.github.andriydruk:rxdnssd:0.9.5'

@andriydruk
Copy link
Owner

Hi, I finally investigated this issue and found that leak of threads might occured because of hang of some query or resolve records operation.
I added timeout for this 2 kind of operations (default value 60 sec).
Also, I added auto-stop for query and resolve records. If you use DNSSD without Rx, you is not obliged to stop this operations in callbacks anymore.

Check out new version https://github.com/andriydruk/RxDNSSD/releases/tag/0.9.7

@namannik
Copy link

Thanks for the update. I'll check it out next time I have a chance.

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

No branches or pull requests

3 participants