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

java.lang.StackOverflowError on HeapAnalyzerService #3

Closed
luciofm opened this issue May 8, 2015 · 17 comments · Fixed by square/haha#4 or #66
Closed

java.lang.StackOverflowError on HeapAnalyzerService #3

luciofm opened this issue May 8, 2015 · 17 comments · Fixed by square/haha#4 or #66

Comments

@luciofm
Copy link

luciofm commented May 8, 2015

After navigating a while through my app I got a StackOverFlowError...

        AndroidRuntime  E  FATAL EXCEPTION: IntentService[HeapAnalyzerService]
                        E  Process: com.weheartit:leakcanary, PID: 14442
                        E  java.lang.StackOverflowError
                        E      at java.io.BufferedOutputStream.write(BufferedOutputStream.java:135)
                        E      at java.io.DataOutputStream.writeInt(DataOutputStream.java:180)
                        E      at java.io.ObjectOutputStream.writeCyclicReference(ObjectOutputStream.java:812)
                        E      at java.io.ObjectOutputStream.dumpCycle(ObjectOutputStream.java:427)
                        E      at java.io.ObjectOutputStream.writeClassDesc(ObjectOutputStream.java:754)
                        E      at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1369)
                        E      at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1671)
                        E      at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1517)
                        E      at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1481)
                        E      at java.io.ObjectOutputStream.writeNewArray(ObjectOutputStream.java:1205)
                        E      at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1662)
                        E      at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1517)
                        E      at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1481)
                        E      at java.io.ObjectOutputStream.writeFieldValues(ObjectOutputStream.java:979)
                        E      at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:368)
                        E      at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1074)
                        E      at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1404)
                        E      at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1671)
                        E      at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1517)
                        E      at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1481)
                        E      at java.util.ArrayList.writeObject(ArrayList.java:648)
                        E      at java.lang.reflect.Method.invokeNative(Native Method)
                        E      at java.lang.reflect.Method.invoke(Method.java:515)
                        E      at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1053)
                        E      at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1404)
                        E      at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1671)
                        E      at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1517)
                        E      at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1481)
                        E      at java.io.ObjectOutputStream.writeFieldValues(ObjectOutputStream.java:979)
                        E      at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:368)
                        E      at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1074)
                        E      at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1404)
                        E      at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1671)
                        E      at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1517)
                        E      at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1481)
                        E      at java.util.ArrayList.writeObject(ArrayList.java:648)
                        E      at java.lang.reflect.Method.invokeNative(Native Method)
                        E      at java.lang.reflect.Method.invoke(Method.java:515)
                        E      at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1053)
                        E      at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1404)
                        E      at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1671)
                        E      at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1517)
                        E      at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1481)
                        E      at java.io.ObjectOutputStream.writeFieldValues(ObjectOutputStream.java:979)
                        E      at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:368)
                        E      at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1074)
                        E      at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1404)
                        E      at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1671)
                        E      at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1517)
                        E      at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1481)
                        E      at java.util.ArrayList.writeObject(ArrayList.java:648)
                        E      at java.lang.reflect.Method.invokeNative(Native Method)
                        E      at java.lang.reflect.Method.invoke(Method.java:515)
                        E      at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1053)
                        E      at java.io.ObjectOutputStrea
@pyricau
Copy link
Member

pyricau commented May 8, 2015

This is very interesting. It's happening in the service process, so that's when we're processing a heap dump.

@luciofm
Copy link
Author

luciofm commented May 8, 2015

It was on my first run with leakcanary enabled... will try to reproduce later...

@pyricau
Copy link
Member

pyricau commented May 8, 2015

Could you find the root of the stack in logcat? I'd like to know in which part of LeakCanary code this happened.

@pyricau
Copy link
Member

pyricau commented May 9, 2015

My best bet here is that this happens when we try to start AbstractAnalysisResultService because we need to pass some serializable data back to the original process (and the stacktrace says write).

HeapDump doesn't have a deep hierarchy. AnalysisResult has LeakTrace and Exception, so basically it could be that LeakTrace has a very long list of LeakTraceElement (but it's an unmodifiable array list so not sure that could trigger it), or Exception has a very deep stacktrace / causes.

I will close for now, please reopen or create a new one if you can get more info.

@pyricau pyricau closed this as completed May 9, 2015
@Maragues
Copy link
Contributor

Hi @pyricau , I also got this StackOverFlow on my first run with LeakCanary. My Logcat is similar but not equal to @luciofm

I/dalvikvm( 1761): threadid=11: stack overflow on call to Ljava/io/SerializationHandleMap;.get:IL
I/dalvikvm( 1761):   method requires 16+20+12=48 bytes, fp is 0x9559b31c (28 left)
I/dalvikvm( 1761):   expanding stack end (0x9559b300 to 0x9559b000)
I/dalvikvm( 1761): Shrank stack (to 0x9559b300, curFrame is 0x9559b488)
W/dalvikvm( 1761): threadid=11: thread exiting with uncaught exception (group=0xa4d00b20)
E/AndroidRuntime( 1761): FATAL EXCEPTION: IntentService[HeapAnalyzerService]
E/AndroidRuntime( 1761): Process: org.microhealth.ostheoarthritis:leakcanary, PID: 1761
E/AndroidRuntime( 1761): java.lang.StackOverflowError
E/AndroidRuntime( 1761):    at java.io.ObjectOutputStream.dumpCycle(ObjectOutputStream.java:425)
E/AndroidRuntime( 1761):    at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1566)
E/AndroidRuntime( 1761):    at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1517)
E/AndroidRuntime( 1761):    at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1481)
E/AndroidRuntime( 1761):    at java.io.ObjectOutputStream.writeFieldValues(ObjectOutputStream.java:979)
E/AndroidRuntime( 1761):    at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:368)
E/AndroidRuntime( 1761):    at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1074)
E/AndroidRuntime( 1761):    at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1404)
E/AndroidRuntime( 1761):    at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1671)
E/AndroidRuntime( 1761):    at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1517)
E/AndroidRuntime( 1761):    at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1481)
E/AndroidRuntime( 1761):    at java.io.ObjectOutputStream.writeNewArray(ObjectOutputStream.java:1205)
E/AndroidRuntime( 1761):    at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1662)
E/AndroidRuntime( 1761):    at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1517)
E/AndroidRuntime( 1761):    at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1481)
E/AndroidRuntime( 1761):    at java.io.ObjectOutputStream.writeFieldValues(ObjectOutputStream.java:979)
E/AndroidRuntime( 1761):    at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:368)
E/AndroidRuntime( 1761):    at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1074)
E/AndroidRuntime( 1761):    at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1404)
E/AndroidRuntime( 1761):    at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1671)
E/AndroidRuntime( 1761):    at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1517)
E/AndroidRuntime( 1761):    at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1481)
E/AndroidRuntime( 1761):    at java.util.ArrayList.writeObject(ArrayList.java:648)
E/AndroidRuntime( 1761):    at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 1761):    at java.lang.reflect.Method.invoke(Method.java:515)
E/AndroidRuntime( 1761):    at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1053)
E/AndroidRuntime( 1761):    at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1404)
E/AndroidRuntime( 1761):    at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1671)
E/AndroidRuntime( 1761):    at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1517)
E/AndroidRuntime( 1761):    at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1481)
E/AndroidRuntime( 1761):    at java.io.ObjectOutputStream.writeFieldValues(ObjectOutputStream.java:979)
E/AndroidRuntime( 1761):    at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:368)
E/AndroidRuntime( 1761):    at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1074)
E/AndroidRuntime( 1761):    at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1404)
E/AndroidRuntime( 1761):    at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1671)
E/AndroidRuntime( 1761):    at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1517)
E/AndroidRuntime( 1761):    at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1481)
E/AndroidRuntime( 1761):    at java.util.ArrayList.writeObject(ArrayList.java:648)
E/AndroidRuntime( 1761):    at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 1761):    at java.lang.reflect.Method.invoke(Method.java:515)
E/AndroidRuntime( 1761):    at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1053)
E/AndroidRuntime( 1761):    at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1404)
E/AndroidRuntime( 1761):    at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1671)
E/AndroidRuntime( 1761):    at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1517)
E/AndroidRuntime( 1761):    at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1481)
E/AndroidRuntime( 1761):    at java.io.ObjectOutputStream.writeFieldValues(ObjectOutputStream.java:979)
E/AndroidRuntime( 1761):    at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:368)
E/AndroidRuntime( 1761):    at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1074)
E/AndroidRuntime( 1761):    at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1404)
E/AndroidRuntime( 1761):    at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1671)
E/AndroidRuntime( 1761):    at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1517)
E/AndroidRuntime( 1761):    at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1481)
E/AndroidRuntime( 1761):    at java.util.ArrayList.writeObject(ArrayList.java:648)
E/AndroidRuntime( 1761):    at java.lang.reflect.Method.i

Let me know if I can help, as I've been able to isolate it to 1 specifc use case.

Plus, after the crash I'm seeing this message in Logcat

D/AndroidHeapDumper( 1256): Could not dump heap, previous analysis still is in progress.

Maybe you can reopen the issue?

@pyricau pyricau reopened this May 11, 2015
@pyricau
Copy link
Member

pyricau commented May 11, 2015

Is this systematic?

@Maragues
Copy link
Contributor

yes, it happens every time.

@swankjesse
Copy link
Contributor

Can you attach a debugger? Would be really handy if you could put a breakpoint in the StackOverflowError constructor to see what chain of objects it's attempting to serialize.

@Maragues
Copy link
Contributor

@swankjesse The crash doesn't happen when I attach a debugger, but it occurs systematically without it.

I'm going to try to add it as a local dependency and see if I can Log something. Any hint?

@Maragues
Copy link
Contributor

It's only happening on Android 4.4.4, it seems to work well on Lollipop. And, one time it also worked well on KitKat. I haven't been able to capture any log, sorry.

I've tested on Genymotion Nexus 4 and a real device One Plus One still on CM 11

@pepyakin
Copy link

@Maragues I bet crash doesn't happen with debugger attached because of this

@vovkab
Copy link

vovkab commented May 11, 2015

Happening to me too on Android 4.3

@vovkab
Copy link

vovkab commented May 11, 2015

Finally got correct stacktrace:

at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1404)
at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1671)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1517)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1481)
at org.eclipse.mat.parser.internal.SnapshotImpl.create(SnapshotImpl.java:184)
at org.eclipse.mat.parser.internal.SnapshotImplBuilder.create(SnapshotImplBuilder.java:94)
at org.eclipse.mat.parser.internal.SnapshotFactory.parse(SnapshotFactory.java:201)
at org.eclipse.mat.parser.internal.SnapshotFactory.openSnapshot(SnapshotFactory.java:106)
at com.squareup.leakcanary.HeapAnalyzer.openSnapshot(HeapAnalyzer.java:136)
at com.squareup.leakcanary.HeapAnalyzer.checkForLeak(HeapAnalyzer.java:89)
at com.squareup.leakcanary.internal.HeapAnalyzerService.onHandleIntent(HeapAnalyzerService.java:57)
at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)

@pyricau
Copy link
Member

pyricau commented May 12, 2015

Thanks @vovkab. Damn, it's in haha. Which means it's going to be a nightmare.

@pyricau
Copy link
Member

pyricau commented May 12, 2015

Culprit: out.writeObject(answer.classCache);

We could spend some time improve the serialized classes to avoid recursive calls. But after looking at it, I realized that the whole point is to save the parsing so that it can be reopened quickly later without reparsing the heapdump. We don't care about that. So we can probably get away with remove that part entirely.

@pyricau
Copy link
Member

pyricau commented May 12, 2015

Fix in HAHA here: square/haha#4

@pyricau
Copy link
Member

pyricau commented May 12, 2015

Not just yet, need to update leakcanary.

pyricau added a commit that referenced this issue May 12, 2015
Updating to HAHA 1.3 which doesn't save its index file any more. Will hopefully resolve #3 (although there might be other issues down the road).
Yky pushed a commit to Yky/leakcanary that referenced this issue Feb 21, 2016
Updating to HAHA 1.3 which doesn't save its index file any more. Will hopefully resolve square#3 (although there might be other issues down the road).
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

Successfully merging a pull request may close this issue.

6 participants