B4J Question ABMaterial: java.nio.channels.ClosedChannelException - how to suppress

JackKirk

Well-Known Member
Licensed User
Longtime User
When I run my ABMaterial web app in release mode I am randomly(?) getting messages of the form:
java.io.IOException: java.nio.channels.ClosedChannelException
at org.eclipse.jetty.util.FutureCallback.block(FutureCallback.java:163)
at org.eclipse.jetty.websocket.common.JettyWebSocketRemoteEndpoint.flush(JettyWebSocketRemoteEndpoint.java:267)
at anywheresoftware.b4j.object.WebSocket.Flush(WebSocket.java:117)
at anywheresoftware.b4j.object.WebSocketModule$Adapter$ThreadHandler.run(WebSocketModule.java:205)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:577)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:317)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
at java.base/java.lang.Thread.run(Thread.java:1589)
Caused by: java.nio.channels.ClosedChannelException
at org.eclipse.jetty.websocket.core.internal.FrameFlusher.<clinit>(FrameFlusher.java:47)
at org.eclipse.jetty.websocket.core.internal.WebSocketConnection.<init>(WebSocketConnection.java:124)
at org.eclipse.jetty.websocket.core.internal.WebSocketConnection.<init>(WebSocketConnection.java:86)
at org.eclipse.jetty.websocket.core.server.internal.AbstractHandshaker.newWebSocketConnection(AbstractHandshaker.java:223)
at org.eclipse.jetty.websocket.core.server.internal.RFC6455Handshaker.createWebSocketConnection(RFC6455Handshaker.java:100)
at org.eclipse.jetty.websocket.core.server.internal.AbstractHandshaker.upgradeRequest(AbstractHandshaker.java:143)
at org.eclipse.jetty.websocket.core.server.internal.HandshakerSelector.upgradeRequest(HandshakerSelector.java:39)
at org.eclipse.jetty.websocket.core.server.WebSocketMappings.upgrade(WebSocketMappings.java:240)
at org.eclipse.jetty.websocket.server.JettyWebSocketServlet.service(JettyWebSocketServlet.java:181)
at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:587)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:764)
at org.eclipse.jetty.servlet.ServletHandler$ChainEnd.doFilter(ServletHandler.java:1630)
at anywheresoftware.b4j.object.JServlet$Handle.run(JServlet.java:151)
at anywheresoftware.b4j.object.JServlet.Handle(JServlet.java:126)
at anywheresoftware.b4j.object.JServlet.doFilter(JServlet.java:88)
at org.eclipse.jetty.servlet.FilterHolder.doFilter(FilterHolder.java:202)
at org.eclipse.jetty.servlet.ServletHandler$Chain.doFilter(ServletHandler.java:1600)
at anywheresoftware.b4j.object.JServlet$Handle.run(JServlet.java:151)
at anywheresoftware.b4j.object.JServlet.Handle(JServlet.java:126)
at anywheresoftware.b4j.object.JServlet.doFilter(JServlet.java:88)
at org.eclipse.jetty.servlet.FilterHolder.doFilter(FilterHolder.java:202)
at org.eclipse.jetty.servlet.ServletHandler$Chain.doFilter(ServletHandler.java:1600)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:506)
at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:221)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1571)
at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:221)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1375)
at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:176)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:463)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1544)
at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:174)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1297)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:129)
at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:141)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:122)
at org.eclipse.jetty.server.Server.handle(Server.java:562)
at org.eclipse.jetty.server.HttpChannel.lambda$handle$0(HttpChannel.java:505)
at org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:762)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:497)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:282)
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:319)
at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:100)
at org.eclipse.jetty.io.ssl.SslConnection$1.run(SslConnection.java:132)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:894)
at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:1038)
... 1 more
According to Erel at:
https://www.b4x.com/android/forum/t...nels-closedchannelexception.99931/post-628850
they can be ignored.

But they are messing up my real time log, can anyone give me some guidance on how to suppress them.

Thanks in anticipation...
 
I'm confused. my app's library settings seem to be:

Name Version Online Path Platform
jServer 4.01 4.03 Internal B4J

Am I on 4.01 or 4.03?

When I turn this entry off, among the available libraries appears:

jServer 4.03 Internal B4J

But if I check that I get the first entry again.
 
Upvote 0
Am I on 4.01 or 4.03?
4.01

Update jserver library


Make sure to copy the files to the internal library folder.
 
Upvote 0
Thanks Don Manfred - I have updated jServer library to 4.03

I'm still confused about what I need to do with b4j_ws.zip - is this in jServer 4.03 or do I have to incorporate it somehow?
 
Upvote 0
I successfully upgraded to jServer 4.03 but am still getting the ClosedChannelException error in my logs.

I added:
B4X:
#PackagerProperty: AdditionalModuleInfoString = provides org.slf4j.spi.SLF4JServiceProvider with org.eclipse.jetty.logging.JettyLoggingServiceProvider;
#PackagerProperty: AdditionalModuleInfoString = provides org.eclipse.jetty.io.ssl.ALPNProcessor.Server with org.eclipse.jetty.alpn.java.server.JDK9ServerALPNProcessor;
#PackagerProperty: AdditionalModuleInfoString = provides org.eclipse.jetty.http.HttpFieldPreEncoder with org.eclipse.jetty.http2.hpack.HpackFieldPreEncoder, org.eclipse.jetty.http.Http1FieldPreEncoder;
#PackagerProperty: AdditionalModuleInfoString = uses org.eclipse.jetty.util.security.CredentialProvider;
#PackagerProperty: AdditionalModuleInfoString = uses org.eclipse.jetty.io.ssl.ALPNProcessor.Server;
#PackagerProperty: IncludedModules = jdk.charsets, jdk.crypto.ec
#CustomBuildAction: After Packager, %WINDIR%\System32\robocopy.exe, www temp\build\bin\www /E
to the #Region Project Attributes of my b4j apps

But I don't use the standalone packager to create an .exe - I use B4JBuilder to create a .jar

I'm assuming the #Region Project Attributes stuff needs altering but how?

Thanks...
 
Upvote 0
to the #Region Project Attributes of my b4j apps

But I don't use the standalone packager to create an .exe - I use B4JBuilder to create a .jar

I'm assuming the #Region Project Attributes stuff needs altering but how?
It is not related. You don't need to make any change.

Can you post the logs?
 
Upvote 0
Can you post the logs?
I think I'm embarrassed - for experimentation purposes I have 2 B4J ABMaterial web apps running on a single AWS EC2 behind an AWS Application Load Balancer - I think I must have recompiled one of them twice and the other nonest.

After recompiling both they now seem to be behaving.

Thanks for your patience...
 
Upvote 0
Can you post the logs?
I spoke too soon, in my logs I am still getting:
(ClosedChannelException) java.nio.channels.ClosedChannelException
java.io.IOException: java.nio.channels.ClosedChannelException
at org.eclipse.jetty.util.FutureCallback.block(FutureCallback.java:163)
at org.eclipse.jetty.websocket.common.JettyWebSocketRemoteEndpoint.flush(JettyWebSocketRemoteEndpoint.java:267)
at anywheresoftware.b4j.object.WebSocket.Flush(WebSocket.java:117)
at anywheresoftware.b4j.object.WebSocketModule$Adapter$ThreadHandler.run(WebSocketModule.java:207)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:577)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:317)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
at java.base/java.lang.Thread.run(Thread.java:1589)
Caused by: java.nio.channels.ClosedChannelException
at org.eclipse.jetty.websocket.core.internal.FrameFlusher.<clinit>(FrameFlusher.java:47)
at org.eclipse.jetty.websocket.core.internal.WebSocketConnection.<init>(WebSocketConnection.java:124)
at org.eclipse.jetty.websocket.core.internal.WebSocketConnection.<init>(WebSocketConnection.java:86)
at org.eclipse.jetty.websocket.core.server.internal.AbstractHandshaker.newWebSocketConnection(AbstractHandshaker.java:223)
at org.eclipse.jetty.websocket.core.server.internal.RFC6455Handshaker.createWebSocketConnection(RFC6455Handshaker.java:100)
at org.eclipse.jetty.websocket.core.server.internal.AbstractHandshaker.upgradeRequest(AbstractHandshaker.java:143)
at org.eclipse.jetty.websocket.core.server.internal.HandshakerSelector.upgradeRequest(HandshakerSelector.java:39)
at org.eclipse.jetty.websocket.core.server.WebSocketMappings.upgrade(WebSocketMappings.java:240)
at org.eclipse.jetty.websocket.server.JettyWebSocketServlet.service(JettyWebSocketServlet.java:181)
at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:587)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:764)
at org.eclipse.jetty.servlet.ServletHandler$ChainEnd.doFilter(ServletHandler.java:1630)
at anywheresoftware.b4j.object.JServlet$Handle.run(JServlet.java:151)
at anywheresoftware.b4j.object.JServlet.Handle(JServlet.java:126)
at anywheresoftware.b4j.object.JServlet.doFilter(JServlet.java:88)
at org.eclipse.jetty.servlet.FilterHolder.doFilter(FilterHolder.java:202)
at org.eclipse.jetty.servlet.ServletHandler$Chain.doFilter(ServletHandler.java:1600)
at anywheresoftware.b4j.object.JServlet$Handle.run(JServlet.java:151)
at anywheresoftware.b4j.object.JServlet.Handle(JServlet.java:126)
at anywheresoftware.b4j.object.JServlet.doFilter(JServlet.java:88)
at org.eclipse.jetty.servlet.FilterHolder.doFilter(FilterHolder.java:202)
at org.eclipse.jetty.servlet.ServletHandler$Chain.doFilter(ServletHandler.java:1600)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:506)
at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:221)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1571)
at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:221)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1375)
at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:176)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:463)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1544)
at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:174)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1297)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:129)
at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:141)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:122)
at org.eclipse.jetty.server.Server.handle(Server.java:562)
at org.eclipse.jetty.server.HttpChannel.lambda$handle$0(HttpChannel.java:505)
at org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:762)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:497)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:282)
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:319)
at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:100)
at org.eclipse.jetty.io.ssl.SslConnection$1.run(SslConnection.java:132)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:894)
at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:1038)
... 1 more
 
Upvote 0
I don't know if this is any help but it seems to be mainly/only(?) happening when I am using javascript to jump from a webpage in my app to something external, these are the js statements that do that:
B4X:
var url = 'xxx://' + wrkguid;
window.location.href = url;

var url = 'https://play.google.com/store/apps/details?id=treetops.app.customer&hl=en&gl=US&referrer=' + wrkguid;
window.open(url, '_blank');

var url = 'https://itunes.apple.com/us/app/treetops-smart-photo-customer/id1405937870?ls=1&mt=8';
window.open(url, '_blank');
the jumps always work though.
 
Upvote 0
If you can reproduce it in a small project then I will probably be able to solve it.
Thanks for the offer Erel but this just keeps getting weirder.

I was initially running a set up like this:

...............user on browser
............................... |
..........................HTTPS
............................... |
...............................V
AWS Application Load Balancer
...............|................................|
........HTTPS.....................HTTPS
...............|................................|
..............V..............................V
WebServer01........WebServer02....<--- both on same AWS EC2 instance, using LetsEncrypt


so I could avoid having to use LetsEncrypt (just another potential failure point) I transitioned my code and set up to:

...............user on browser
............................... |
..........................HTTPS
............................... |
...............................V
AWS Application Load Balancer
...............|................................|
........HTTP.......................HTTP....<--- change
...............|................................|
..............V..............................V
WebServer01........WebServer02....<--- both on same AWS EC2 instance, NOT using LetsEncrypt

which is apparently a quite common setup.

But now during testing on 4 devices (2 iPhones and 2 Pixels) the problem seems to have disappeared.

Is this a possible result or am I just premature in my reporting?
 
Last edited:
Upvote 0
I guess that you will still encounter these logs from time to time. Unexpected disconnections are expected to happen.
Erel, I now have some time to ferret out these last remaining error messages from my logs.

I know a small example would be nice but I don't see how that is possible to do - would you be willing to look at the complete project?
 
Upvote 0
Back
Top