{"action":"created","issue":{"url":"https://api.github.com/repos/phax/as2-lib/issues/24","repository_url":"https://api.github.com/repos/phax/as2-lib","labels_url":"https://api.github.com/repos/phax/as2-lib/issues/24/labels{/name}","comments_url":"https://api.github.com/repos/phax/as2-lib/issues/24/comments","events_url":"https://api.github.com/repos/phax/as2-lib/issues/24/events","html_url":"https://github.com/phax/as2-lib/issues/24","id":166831890,"number":24,"title":"Retries cause OOM when creating stacktrace","user":{"login":"undernorthernsky","id":1017441,"avatar_url":"https://avatars.githubusercontent.com/u/1017441?v=3","gravatar_id":"","url":"https://api.github.com/users/undernorthernsky","html_url":"https://github.com/undernorthernsky","followers_url":"https://api.github.com/users/undernorthernsky/followers","following_url":"https://api.github.com/users/undernorthernsky/following{/other_user}","gists_url":"https://api.github.com/users/undernorthernsky/gists{/gist_id}","starred_url":"https://api.github.com/users/undernorthernsky/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/undernorthernsky/subscriptions","organizations_url":"https://api.github.com/users/undernorthernsky/orgs","repos_url":"https://api.github.com/users/undernorthernsky/repos","events_url":"https://api.github.com/users/undernorthernsky/events{/privacy}","received_events_url":"https://api.github.com/users/undernorthernsky/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/phax/as2-lib/labels/bug","name":"bug","color":"fc2929"}],"state":"open","locked":false,"assignee":{"login":"phax","id":196219,"avatar_url":"https://avatars.githubusercontent.com/u/196219?v=3","gravatar_id":"","url":"https://api.github.com/users/phax","html_url":"https://github.com/phax","followers_url":"https://api.github.com/users/phax/followers","following_url":"https://api.github.com/users/phax/following{/other_user}","gists_url":"https://api.github.com/users/phax/gists{/gist_id}","starred_url":"https://api.github.com/users/phax/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/phax/subscriptions","organizations_url":"https://api.github.com/users/phax/orgs","repos_url":"https://api.github.com/users/phax/repos","events_url":"https://api.github.com/users/phax/events{/privacy}","received_events_url":"https://api.github.com/users/phax/received_events","type":"User","site_admin":false},"assignees":[{"login":"phax","id":196219,"avatar_url":"https://avatars.githubusercontent.com/u/196219?v=3","gravatar_id":"","url":"https://api.github.com/users/phax","html_url":"https://github.com/phax","followers_url":"https://api.github.com/users/phax/followers","following_url":"https://api.github.com/users/phax/following{/other_user}","gists_url":"https://api.github.com/users/phax/gists{/gist_id}","starred_url":"https://api.github.com/users/phax/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/phax/subscriptions","organizations_url":"https://api.github.com/users/phax/orgs","repos_url":"https://api.github.com/users/phax/repos","events_url":"https://api.github.com/users/phax/events{/privacy}","received_events_url":"https://api.github.com/users/phax/received_events","type":"User","site_admin":false}],"milestone":null,"comments":0,"created_at":"2016-07-21T14:23:16Z","updated_at":"2016-07-21T16:52:01Z","closed_at":null,"body":"This is similar to #16; the scenario is repeated failure to send a message.\r\n\r\nThe final exception isn't too interesting; but anyway:\r\n\r\n```\r\njava.lang.OutOfMemoryError: Java heap space\r\n\tat java.util.Arrays.copyOf(Arrays.java:3332)\r\n\tat java.lang.AbstractStringBuilder.expandCapacity(AbstractStringBuilder.java:137)\r\n\tat java.lang.AbstractStringBuilder.ensureCapacityInternal(AbstractStringBuilder.java:121)\r\n\tat java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:421)\r\n\tat java.lang.StringBuilder.append(StringBuilder.java:136)\r\n\tat com.helger.as2lib.processor.ProcessorException._getMessage(ProcessorException.java:63)\r\n\tat com.helger.as2lib.processor.ProcessorException.<init>(ProcessorException.java:74)\r\n\tat com.helger.as2lib.processor.DefaultMessageProcessor.handle(DefaultMessageProcessor.java:151)\r\n\tat com.helger.as2lib.processor.resender.ImmediateResenderModule.handle(ImmediateResenderModule.java:93)\r\n\tat com.helger.as2lib.processor.DefaultMessageProcessor.handle(DefaultMessageProcessor.java:142)\r\n\tat com.helger.as2lib.processor.sender.AbstractSenderModule.doResend(AbstractSenderModule.java:148)\r\n\tat com.helger.as2lib.processor.sender.AS2SenderModule.handle(AS2SenderModule.java:731)\r\n```\r\n\r\nThe problem seems to be the recursive chain of calls: `AS2SenderModule -> DefaultMessageProcessor -> ResenderModule -> DefaultMessageProcessor -> AS2SenderModule -> ...`.\r\n\r\nEach time the exception is caught in AS2SenderModule, wrapped, stashed and rethrown if the next attempt (`doResend`) fails again; then caught again in `DefaultMessageProcessor` and rethrown as a ProcessorException.\r\n\r\nThis is the length of `getStackAsString()` in `ProcessorException::_getMessage`:\r\n\r\n```\r\ntrace length: 11065\r\ntrace length: 20294\r\ntrace length: 40436\r\ntrace length: 80638\r\ntrace length: 161126\r\ntrace length: 322018\r\ntrace length: 643886\r\ntrace length: 1287538\r\ntrace length: 2574926\r\ntrace length: 5149618\r\ntrace length: 10299086\r\ntrace length: 20597938\r\ntrace length: 41195726\r\ntrace length: 82391218\r\ntrace length: 164782286\r\n```\r\n\r\nI don't see a \"good\" way to avoid the geometric increase; for our usage the following works, but aborting early might not be correct in the general case.\r\n\r\n```\r\n--- a/as2-lib/src/main/java/com/helger/as2lib/processor/DefaultMessageProcessor.java\r\n+++ b/as2-lib/src/main/java/com/helger/as2lib/processor/DefaultMessageProcessor.java\r\n@@ -141,6 +141,9 @@ public class DefaultMessageProcessor extends AbstractMessageProcessor\r\n           bModuleFound = true;\r\n           aModule.handle (sAction, aMsg, aOptions);\r\n         }\r\n+        catch (final ProcessorException ex) {\r\n+          throw ex;\r\n+        }\r\n         catch (final OpenAS2Exception ex)\r\n         {\r\n           aCauses.add (ex);\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/phax/as2-lib/issues/comments/234314634","html_url":"https://github.com/phax/as2-lib/issues/24#issuecomment-234314634","issue_url":"https://api.github.com/repos/phax/as2-lib/issues/24","id":234314634,"user":{"login":"phax","id":196219,"avatar_url":"https://avatars.githubusercontent.com/u/196219?v=3","gravatar_id":"","url":"https://api.github.com/users/phax","html_url":"https://github.com/phax","followers_url":"https://api.github.com/users/phax/followers","following_url":"https://api.github.com/users/phax/following{/other_user}","gists_url":"https://api.github.com/users/phax/gists{/gist_id}","starred_url":"https://api.github.com/users/phax/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/phax/subscriptions","organizations_url":"https://api.github.com/users/phax/orgs","repos_url":"https://api.github.com/users/phax/repos","events_url":"https://api.github.com/users/phax/events{/privacy}","received_events_url":"https://api.github.com/users/phax/received_events","type":"User","site_admin":false},"created_at":"2016-07-21T16:52:00Z","updated_at":"2016-07-21T16:52:00Z","body":"And if you don't run in an OOM, you will sooner or later run in an StackOverflowException.\r\nWhat I could do, is to create an \"AsyncMessageProcessor\" that handles the messages asynchronously (so dispatching happens in a separate thread). This would avoid the stack overflow and the OOM because the stack would always be fixed sized.\r\nI would do this for the current HEAD which targets JDK 8. Does that sound reasonable to you?"}}
{"actor":{"display_login":"phax"}}