B4J Question [B4J Server] Server not response after some time

billzhan

Active Member
Licensed User
Longtime User
Hi,

I have a B4J server(http and websocket) running, but it stops to response after some time ( a day/week ). I've test it on Linux(VPS and laptop) and Windows 7, similar things.

When I inspect the server with tools like VisualJVM, JVM is still running and manual GC works. No memory leaks and exceptions in the logs. Requests to ws/handler/static files receive no response.

Threads dump shows that the "main" thread doesn't exist anymore.

Any hints will be appreciated.

Update : solved. See post #9
 

Attachments

  • jcmd.Threaddump.zip
    12.7 KB · Views: 160
Last edited:

billzhan

Active Member
Licensed User
Longtime User
The "main" thread doesn't exist in the thread dump, is this a problem?

I use something similar to this one:
https://www.b4x.com/android/forum/threads/creating-a-proxy.63292/#post-400026

B4X:
Sub Class_Globals
  Private mResp As ServletResponse
  Private ispost As Boolean
End Sub 

Public Sub Initialize

End Sub

Sub Handle(req As ServletRequest, resp As ServletResponse)
   
    Dim httpmethod As String = req.Method

    mResp = resp
    Dim j As HttpJob    'okhttp
    j.Initialize("j", Me)
    If httpmethod.ToLowerCase = "post" Then
        ispost = True
        j.Post... 
    Else
        ispost = False
        j.Download(...)
    End If
       
    StartMessageLoop  
End Sub

Sub JobDone(Job As HttpJob)
    If Job.Success Then
     If ispost Then
        File.Copy2(Job.GetInputStream, mResp.OutputStream)
     Else
        mResp.Write("< json string >")
     End If  
    Else
     mResp.SendError(500, Job.ErrorMessage)
    End If
    StopMessageLoop  
End Sub
 
Upvote 0

billzhan

Active Member
Licensed User
Longtime User
Yes, I have updated to 4.21 jCore.

I use a B4J wsclient within each websocket thread (ws relay), but there is no MessageLoop in websocket threads.

For now I am trying to check the server health periodically, the jar should be restarted when necessary.
 
Upvote 0

billzhan

Active Member
Licensed User
Longtime User
The code posted is the same structure as the one I used in ShinyFolderHandler module. I am trying to make a reproducible example.

I checked the log file which is written by a timer every 20sec in the main thread, it shows that the main thread was not running (when server stopped to response)
 
Upvote 0

billzhan

Active Member
Licensed User
Longtime User
I've found that an exception was thrown a timer_tick sub (in the main thread) just before the server stop to response. It's caused by an null pointer exception when access to a key (in a threadsafe map) which is removed from other threads.

Server works properly after fixed this bug.
 
Upvote 0
Top