getappmap / appmap-java

AppMap client agent for Java
Other
77 stars 14 forks source link

ConcurrentAccessException on CodeObject.children #30

Open apotterri opened 3 years ago

apotterri commented 3 years ago

Hmm. Perhaps this is the cause, and if it is I believe the call site can be synchronized to avoid making CodeObject/CodeObjectTree thread safe: https://github.com/applandinc/appmap-java/blob/less-mem_20200817/src/main/java/com/appland/appmap/record/Recorder.java#L110-L113

In short, writeEvent used to be synchronized. It's no longer synchronized due to the fact that we can encounter a lock when calling toString into the client application. It's certainly worth looking into. I'll defer to you @apotterri if you'd like to look into it now or as a follow on item.

_Originally posted by @dustinbyrne in https://github.com/applandinc/appmap-java/pull/29#discussion_r475896188_

ta-Bruce commented 3 years ago

This is also encountered with https://github.com/land-of-apps/jenkins/blob/master/cli/src/test/java/hudson/cli/PlainCLIProtocolTest.java while running test goal on jenkins.

Below is the stack trace printed to console: [INFO] Running hudson.cli.PlainCLIProtocolTest Aug 26, 2020 1:30:49 AM hudson.cli.PlainCLIProtocol$FramedReader run WARNING: null java.util.ConcurrentModificationException at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:911) at java.util.ArrayList$Itr.next(ArrayList.java:861) at com.appland.appmap.output.v1.CodeObject.findChildBySubstring(CodeObject.java:274) at com.appland.appmap.record.CodeObjectTree.getMethodBranch(CodeObjectTree.java:98) at com.appland.appmap.record.Recorder.writeEvent(Recorder.java:110) at com.appland.appmap.record.Recorder.queueEvent(Recorder.java:154) at com.appland.appmap.record.Recorder.add(Recorder.java:197) at com.appland.appmap.process.hooks.MethodCall.handle(MethodCall.java:26) at hudson.cli.FlightRecorderInputStream.read(FlightRecorderInputStream.java) at java.io.DataInputStream.readInt(DataInputStream.java:387) at hudson.cli.PlainCLIProtocol$FramedReader.run(PlainCLIProtocol.java:130)

Furthermore, the program is stuck at https://github.com/land-of-apps/jenkins/blob/b64b4aa50d349a74368503a9dca53a0d85fe1d17/cli/src/test/java/hudson/cli/PlainCLIProtocolTest.java#L129 which could be seen by thread dump.

I had to kill the process and re execute the same command. This is not encountered each and every time though.