B4J Question Crash WebApp in debug mode

alwaysbusy

Expert
Licensed User
Longtime User
I'm receiving this error sometimes when I try to start to run my app in debug mode. (runs ok the first time, I kill the process and then restart). After this, it ends. Does not seem to happen when in Release mode. After that, I can't even run it any more. It compiles, starts and stops. The error is not shown anymore. Only a computer restart seems to help.

log:

B4X:
java.lang.ExceptionInInitializerError
Caused by: java.lang.RuntimeException: java.net.SocketException: Connection reset
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:114)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:82)
    at b4j.example.main.<clinit>(main.java:17)
Caused by: java.net.SocketException: Connection reset
    at java.net.SocketInputStream.read(SocketInputStream.java:209)
    at java.net.SocketInputStream.read(SocketInputStream.java:141)
    at java.io.BufferedInputStream.fill(BufferedInputStream.java:246)
    at java.io.BufferedInputStream.read(BufferedInputStream.java:265)
    at java.io.DataInputStream.readByte(DataInputStream.java:265)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:217)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:156)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
    ... 2 more
Exception in thread "main"
 

billzhan

Active Member
Licensed User
Longtime User
@alwaysbusy

It maybe related to an unconfirmed bug from b4j 2.8.
https://www.b4x.com/android/forum/threads/error-in-debug-mode-b4j-version-2-8.50495/page-3

I am trying to load an old old project wiith 3.7.1 , similar error.

It happens when :
1. Large project.
2. Breakpoints in handlers/classes (except the main thread)
3. Run in debug mode , debug will not start ( Not every time)
4. Run in release mode , OK.
5. After clear all breakpoints, runs well in debug mode.


You can try to clear all breakpoints .

Updte : It seems that VirtualMachineArgs setting affect it. When VirtualMachineArgs is small and breakpoints are set , this happens more offen.

example :
#VirtualMachineArgs: -Xms224m -Xmx224m with breakpoint : not working
#VirtualMachineArgs: -Xms224m -Xmx224m without breakpoint : working sometimes
 
Last edited:
Upvote 0

alwaysbusy

Expert
Licensed User
Longtime User
@billzhan Yes, took me some time to figure out but it looks like it was putting the breakpoint in de Handler that was causing it. I know it was metioned some time ago, but completely forgot about this. Moreover, I did exactly the same in Erels server example and got the same error, never realizing doing the breakpoint to find the bug was actually causing it :)

@Erel When this kind of error happens, there is nothing in the Task Manager making it even weirder to find.
 
Upvote 0

alwaysbusy

Expert
Licensed User
Longtime User
I'll try to reproduce it again but a lot has changed in my app since then. I'm under the impression it was my app after all which caused your project to behave the same after my crash.

This is the code in my handler now. I remember having trouble with the lines:

B4X:
MaxSize = req.GetSession.GetAttribute("abmmaxsize")
I got an error where it could not parse 'null' to float (or double)
B4X:
Dim filePart As Part = data.Get("upl")          
fileName =  filePart.SubmittedFilename
Here I had data.Get("file1") and it should've been "upl". Because it was wrong filePart was null so the next line crashed. The program stopped and then I had the error as described above.

B4X:
'Handler class
Sub Class_Globals
    Dim ABM As ABMaterial
End Sub

Public Sub Initialize
   
End Sub

Sub Handle(req As ServletRequest, resp As ServletResponse)   
    'get the callback page from the session (multiple modules can use this handler)
    Dim callback As Object = req.GetSession.GetAttribute("abmcallback")   
    Dim downloadfolder As String = File.Combine(File.DirApp, req.GetSession.GetAttribute("abmdownloadfolder"))
    Dim MaxSize As Int
    Try
        MaxSize = req.GetSession.GetAttribute("abmmaxsize")
    Catch           
        resp.SendError(500, LastException.Message)
        Return
    End Try
    Dim data As Map   
    Dim fileName As String
    Dim tmpFileName As String
   
    Try
        data = req.GetMultipartData(downloadfolder, MaxSize)       
        Dim filePart As Part = data.Get("upl")           
        fileName =  filePart.SubmittedFilename       
        tmpFileName = filePart.TempFile       
        If ABM.HandleUpload(downloadfolder, tmpFileName, fileName) Then   
            Log("success")       
            CallSubDelayed3(callback, "Page_FileUploaded", fileName, True)
        Else   
            Log("fail")       
            CallSubDelayed3(callback, "Page_FileUploaded", fileName, False)
        End If       
    Catch           
        resp.SendError(500, LastException.Message)
        CallSubDelayed3(callback, "Page_FileUploaded", LastException.Message , False)
        fileName = "LastException.Message"   
    End Try       
End Sub

Sorry I can't be more helpfull for now, but as said, I'll try to reproduce it.
 
Upvote 0

billyrudi

Active Member
Licensed User
Longtime User
Erel i saw that if i tray to start meny times the app in debug mode after the fisrt error message at a certain point the debug start.
it seems as if the web browser maintains an open connection... but i'm not an expert in this... ;):p
 
Upvote 0

billzhan

Active Member
Licensed User
Longtime User
It's not easy to reproduce this issue, even in the same pc.

Sometimes, if one breakpoint (in handlers) is set, debugger runs. Then add more breakpoints, it doesn't work.

Guess: something to do with JVM memory management, the debugger JVMs are killed somehow

To run in debug mode, tips may help :
1. clear all breakpoints
2. try to change #VirtualMachineArgs setting (to different values)

I can now work with the project with the tips.
 
Upvote 0
Top