B4J Question Server Handler Error

ilan

Expert
Licensed User
Longtime User
hi

i am getting errors in the logs when making a request to a server handler.

the problem is that it does not happen always but what i noticed is that it happens always when the server is running for the first time.
making the request again does not fire those logs:

Waiting for debugger to connect...
Program started.
2021-08-08 03:23:34.478:INFO::main: Logging initialized @631ms to org.eclipse.jetty.util.log.StdErrLog
2021-08-08 03:23:34.626:INFO:eek:ejs.Server:main: jetty-9.4.z-SNAPSHOT; built: 2018-05-03T15:56:21.710Z; git: daa59876e6f384329b122929e70a80934569428c; jvm 1.8.0_261-b12
2021-08-08 03:23:34.663:INFO:eek:ejs.session:main: DefaultSessionIdManager workerName=node0
2021-08-08 03:23:34.663:INFO:eek:ejs.session:main: No SessionScavenger set, using defaults
2021-08-08 03:23:34.664:INFO:eek:ejs.session:main: node0 Scavenging every 600000ms
2021-08-08 03:23:34.699:INFO:eek:ejsh.ContextHandler:main: Started o.e.j.s.ServletContextHandler@3108bc{/,file:///D:/F/Stores%20-%20Web%20Pages/Cell4U/DashBoard/Objects/www/,AVAILABLE}
2021-08-08 03:23:34.703:INFO:eek:ejs.AbstractNCSARequestLog:main: Opened D:\F\Stores - Web Pages\Cell4U\DashBoard\Objects\logs\b4j-2021_08_08.request.log
2021-08-08 03:23:34.904:INFO:eek:ejs.AbstractConnector:main: Started ServerConnector@2b9627bc{HTTP/1.1,[http/1.1]}{0.0.0.0:80}
2021-08-08 03:23:34.918:INFO:eek:ejus.SslContextFactory:main: x509=X509@551aa95a(jetty,h=[],w=[]) for SslContextFactory@35d176f7[provider=null,keyStore=file:///D:/F/Stores%20-%20Web%20Pages/Cell4U/DashBoard/Objects/keystore,trustStore=null]
2021-08-08 03:23:35.248:INFO:eek:ejs.AbstractConnector:main: Started ServerConnector@14a2f921{SSL,[ssl, http/1.1]}{0.0.0.0:443}
2021-08-08 03:23:35.248:INFO:eek:ejs.Server:main: Started @1404ms
Emulated network latency: 100ms
java.nio.channels.ClosedChannelException
at org.eclipse.jetty.util.IteratingCallback.close(IteratingCallback.java:427)
at org.eclipse.jetty.server.HttpConnection.onClose(HttpConnection.java:507)
at org.eclipse.jetty.io.ssl.SslConnection.onClose(SslConnection.java:257)
at org.eclipse.jetty.io.SelectorManager.connectionClosed(SelectorManager.java:341)
at org.eclipse.jetty.io.ManagedSelector$DestroyEndPoint.run(ManagedSelector.java:874)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:760)
at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:678)
at java.lang.Thread.run(Thread.java:748)

what could be the reason for that?
i am calling the handler from an email url.
 

OliverA

Expert
Licensed User
Longtime User
You may have posted in wrong forum. Does it happen in release mode also (looks like you are running the server in debug mode)
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
Upvote 0

ilan

Expert
Licensed User
Longtime User
You may have posted in wrong forum. Does it happen in release mode also (looks like you are running the server in debug mode)

yes, it is happening also in release mode.
sometimes i also get this error:

java.nio.channels.ClosedChannelException
at org.eclipse.jetty.util.IteratingCallback.close(IteratingCallback.java:427)
at org.eclipse.jetty.server.HttpConnection.onClose(HttpConnection.java:507)
at org.eclipse.jetty.io.ssl.SslConnection.onClose(SslConnection.java:257)
at org.eclipse.jetty.io.SelectorManager.connectionClosed(SelectorManager.java:341)
at org.eclipse.jetty.io.ManagedSelector$DestroyEndPoint.run(ManagedSelector.java:874)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:760)
at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:678)
at java.lang.Thread.run(Thread.java:748)
org.eclipse.jetty.io.EofException
at org.eclipse.jetty.io.ChannelEndPoint.flush(ChannelEndPoint.java:286)
at org.eclipse.jetty.io.ssl.SslConnection$DecryptedEndPoint.flush(SslConnection.java:1044)
at org.eclipse.jetty.io.WriteFlusher.flush(WriteFlusher.java:429)
at org.eclipse.jetty.io.WriteFlusher.write(WriteFlusher.java:323)
at org.eclipse.jetty.io.AbstractEndPoint.write(AbstractEndPoint.java:380)
at org.eclipse.jetty.server.HttpConnection$SendCallback.process(HttpConnection.java:798)
at org.eclipse.jetty.util.IteratingCallback.processing(IteratingCallback.java:241)
at org.eclipse.jetty.util.IteratingCallback.iterate(IteratingCallback.java:224)
at org.eclipse.jetty.server.HttpConnection.send(HttpConnection.java:538)
at org.eclipse.jetty.server.HttpChannel.sendResponse(HttpChannel.java:787)
at org.eclipse.jetty.server.HttpChannel.write(HttpChannel.java:843)
at org.eclipse.jetty.server.HttpOutput.write(HttpOutput.java:240)
at org.eclipse.jetty.server.HttpOutput.sendContent(HttpOutput.java:777)
at org.eclipse.jetty.server.HttpOutput.sendContent(HttpOutput.java:876)
at org.eclipse.jetty.server.HttpOutput.sendContent(HttpOutput.java:753)
at org.eclipse.jetty.server.ResourceService.sendData(ResourceService.java:732)
at org.eclipse.jetty.server.ResourceService.doGet(ResourceService.java:295)
at org.eclipse.jetty.servlet.DefaultServlet.doGet(DefaultServlet.java:458)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:687)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:865)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1655)
at anywheresoftware.b4j.object.JServlet$Handle.run(JServlet.java:135)
at anywheresoftware.b4j.object.JServlet.Handle(JServlet.java:110)
at anywheresoftware.b4j.object.JServlet.doFilter(JServlet.java:72)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1642)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:533)
at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:255)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1595)
at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:255)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1253)
at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:203)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:473)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1564)
at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:201)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1155)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:144)
at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:126)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
at org.eclipse.jetty.server.Server.handle(Server.java:531)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:352)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:260)
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:281)
at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:102)
at org.eclipse.jetty.io.ssl.SslConnection.onFillable(SslConnection.java:291)
at org.eclipse.jetty.io.ssl.SslConnection$3.succeeded(SslConnection.java:151)
at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:102)
at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:118)
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:333)
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:310)
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:168)
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:126)
at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:366)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:760)
at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:678)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.io.IOException: An established connection was aborted by the software in your host machine
at sun.nio.ch.SocketDispatcher.write0(Native Method)
at sun.nio.ch.SocketDispatcher.write(SocketDispatcher.java:51)
at sun.nio.ch.IOUtil.writeFromNativeBuffer(IOUtil.java:93)
at sun.nio.ch.IOUtil.write(IOUtil.java:51)
at sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:469)
at org.eclipse.jetty.io.ChannelEndPoint.flush(ChannelEndPoint.java:264)
... 55 more
Waiting for value (2 ms)
Waiting for value (0 ms)
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
If it only happens during start up of the server, it could be a timing issue where request are coming in, but the server is not 100% ready and connections are closed either on client side or server side. Also, such errors can now and then occur during operations due to sporadic network connection failures. The only time to worry about them is if a pattern can be established that certain request cause such failures repeatedly.
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
If it only happens during start up of the server, it could be a timing issue where request are coming in, but the server is not 100% ready and connections are closed either on client side or server side. Also, such errors can now and then occur during operations due to sporadic network connection failures. The only time to worry about them is if a pattern can be established that certain request cause such failures repeatedly.

i can reproduce this error.
every time i restart the server and connect to the Server handler by clicking on a link that directs me to that page i get this error.

this is the relevant code:

B4X:
'Handler class
Sub Class_Globals
   
End Sub

Public Sub Initialize
   
End Sub

Sub Handle(req As ServletRequest, resp As ServletResponse)
    Try
        Dim senderUser As String = req.GetParameter("user")
        Dim senderKey As String = req.GetParameter("key")
        Dim userresetkey As String
        userresetkey = Main.sql1.ExecQuerySingleResult2("SELECT resetpasskey FROM users WHERE username = ?", Array As String(senderUser))
               
        Dim bc As BCrypt
        If bc.CheckPW(senderKey & Main.enckey,userresetkey) Then
            resp.AddCookie(js_code.addCookie("user",bc.HashPW(senderUser),-1,True))
            resp.AddCookie(js_code.addCookie("key",senderKey,-1,True))
            resp.SendRedirect("/rp")
        Else
            resp.AddCookie(js_code.addCookie("user","",0,True)) 'reset cookie
            resp.AddCookie(js_code.addCookie("key","",0,True)) 'reset cookie
            resp.SendError(500, LastException.Message)
        End If
    Catch
        resp.SendError(500, LastException.Message)
        Log(LastException)
    End Try
End Sub

/rp will redirect to a websocket class.
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
/rp will redirect to a websocket class.
I'm pretty sure you need to redirect to a HTML page that incorporates the b4j_ws.js file and the HTML page then connects to the /rp websocket module.
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
First, thank Oliver for helping :)

I'm pretty sure you need to redirect to a HTML page that incorporates the b4j_ws.js file and the HTML page then connects to the /rp websocket module.

so it does not work like this. i am not connecting to the WebSocket module. rp is the path that is basically a folder that contains some style.css/js and the relevant index.html file. so when the index.html file is loaded the connection is happing AFTER the page was loaded so I am calling an HTML page by directing to /rp

thanx
 
Upvote 0
Top