B4J Question java.lang.RuntimeException: Resumable sub already completed

prajinpraveen

Active Member
Licensed User
Longtime User
Hello all,

I see there are a few posts on the same topic, I couldn't exactly find the solution.

Here is my scenario. I am calling a Resumable sub within a Resumable sub

resumable sub not completed:
wait for (ABMShared.AddAttachment1(FileName,page.ws.Session, strattachsource,stageid,False)) Complete(attachmentid As List)

Public Sub AddAttachment1(filename As String,sss As HttpSession,strattachsource As String, stageid As Int,isnew As Boolean) As ResumableSub
    Wait For (GetAttachmentVersion1(recordid,strfilepath,filename)) Complete(versionnumber As Double)
    Log("versionnumber1 " & versionnumber)        ' << this is NOT logged
End Sub

Sub GetAttachmentVersion1(recordid As Int,filepath As String,filename As String) As ResumableSub
    Dim versionnumber As Double = 0
    Log("versionnumber " & versionnumber)        ' << this is logged
    Return versionnumber
End Sub

Error Log :
Error log:
java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: Resumable sub already completed
    at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:496)
    at anywheresoftware.b4a.keywords.Common.access$0(Common.java:467)
    at anywheresoftware.b4a.keywords.Common$CallSubDelayedHelper.run(Common.java:541)
    at anywheresoftware.b4a.keywords.SimpleMessageLoop.runMessageLoop(SimpleMessageLoop.java:30)
    at anywheresoftware.b4a.StandardBA.startMessageLoop(StandardBA.java:26)
    at anywheresoftware.b4j.object.WebSocketModule$Adapter$ThreadHandler.run(WebSocketModule.java:191)
    at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.RuntimeException: java.lang.RuntimeException: Resumable sub already completed
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:120)
    at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:487)
    ... 10 more
Caused by: java.lang.RuntimeException: Resumable sub already completed
    at anywheresoftware.b4a.keywords.Common.WaitFor(Common.java:1041)
    at dmsqa.abmshared$ResumableSub_AddAttachment.resume(abmshared.java:1204)
    at dmsqa.abmshared._addattachment(abmshared.java:1038)
    at dmsqa.frmrecords$ResumableSub_Page_FileUploaded.resume(frmrecords.java:5891)
    at dmsqa.frmrecords._page_fileuploaded(frmrecords.java:5843)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:91)

This happens when the app is started and the first wait for is called for the first 2 times. When the first wait for is called the third time ( user tries to upload file the third time as it failed the first two times, the error disappears )

Thank you
 
Last edited:

prajinpraveen

Active Member
Licensed User
Longtime User
Maybe i spoke a little too soon.

Adding sleep(100) in the second sub before the return seems to have resolved the issue. I am going to run tests this week and feedback if there is any change.

Second sub:
Sub GetAttachmentVersion1(recordid As Int,filepath As String,filename As String) As ResumableSub
    Dim versionnumber As Double = 0
    Log("versionnumber " & versionnumber)        ' << this is logged
    sleep(100)                  ' << ADD THIS
    Return versionnumber
End Sub
 
Upvote 0

prajinpraveen

Active Member
Licensed User
Longtime User
Thanks Erel. I got excited that the issue is resolved :)

You are right. the two subs are in a code module.
Sub AddAttachment1 and Sub GetAttachmentVersion1 are in a code module.
Web socket calls the first Wait for

wait for (ABMShared.AddAttachment1(FileName,page.ws.Session, strattachsource,stageid,False)) Complete(attachmentid As List)

is there any other information that you would like to know?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
. the two subs are in a code module
Code modules can not use any events. Move the Code to a Activity or a Service or a Class and instantiate the class in a Service or an Activity.
My fault. I didn´t realized it is a B4J question; sorry.
 
Last edited:
Upvote 0
Top