B4J Question IOException Error - TimeoutException

ilan

Expert
Licensed User
Longtime User
Hi,

i am using in my new webapp the jserver library and after getting a request from my webpage to the b4j server and making the redirection to a site showing a video file i am getting this error:

2021-03-15 14:58:20.761:WARN:eek:ejs.HttpChannel:qtp683287027-20: /mc/movies/1.mp4
java.io.IOException: java.util.concurrent.TimeoutException: Idle timeout expired: 30001/30000 ms
at org.eclipse.jetty.util.SharedBlockingCallback$Blocker.block(SharedBlockingCallback.java:226)
at org.eclipse.jetty.server.HttpOutput.write(HttpOutput.java:217)
at org.eclipse.jetty.server.HttpOutput.write(HttpOutput.java:536)
at org.eclipse.jetty.util.IO.copy(IO.java:164)
at org.eclipse.jetty.util.resource.Resource.writeTo(Resource.java:682)
at org.eclipse.jetty.server.ResourceService.sendData(ResourceService.java:763)
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.doHandle(ServletHandler.java:535)
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.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.util.concurrent.TimeoutException: Idle timeout expired: 30001/30000 ms
at org.eclipse.jetty.io.IdleTimeout.checkIdleTimeout(IdleTimeout.java:166)
at org.eclipse.jetty.io.IdleTimeout$1.run(IdleTimeout.java:50)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)

it does not happen always only sometime and i tested it only in debug mode, what could be the reason for that?
(the server keeps working, it does not crash and i get still navigate in my web pages)

thanx
 

ilan

Expert
Licensed User
Longtime User
You will get all kinds of connection errors in the server. Maybe the client closed the browser tab and the request was abandoned.

the client redirects to a new site with the response.sendredirect() mthod.
this is the relevant code:

B4X:
Sub Handle(req As ServletRequest, resp As ServletResponse)
    Try
        Dim prevHTML As String = File.ReadString(Main.templatePath,"preview.tmp")
        Dim movieId As Int = req.ParameterMap.GetKeyAt(0) 'get name parameter
 
'        Dim arr() As String = req.ParameterMap.GetValueAt(0)
'        Log(arr(0)) 'get value parameter
 
        Dim mymovie As movie = Main.moviesMap.Get(movieId)
        prevHTML = prevHTML.Replace("<%=prev_title%>",mymovie.m_name)
        Dim vidHtml As String = $"
                <video id="prev_vid" controls width="800px">
                <source src="${mymovie.m_path}" type="video/mp4">
                Your browser does Not support this video Type.
                </video>
                "$
        prevHTML = prevHTML.Replace("<%=prev_time%>",mymovie.m_length)
        prevHTML = prevHTML.Replace("<%=prev_vidsource%>",vidHtml)
        prevHTML = prevHTML.Replace("<%=prev_p%>",mymovie.m_desc)
        
        'create temp file to preview the movie
        Dim tempFile As String = $"temp_${Main.tempNr}.html"$
        Main.tempNr = Main.tempNr + 1
        File.WriteString(Main.mediacenterPath,tempFile,prevHTML)
        resp.SendRedirect("/mc/"&tempFile)
    Catch
        Log(LastException)
    End Try
End Sub

do you see something wrong ?

thank you erel
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0

ilan

Expert
Licensed User
Longtime User
thank you for your reply.

Using Map.GetKeyAt is always wrong, especially in this case where the parameters can change in all kinds of ways.

i agree with you, it would be great to retrieve a map will keys: values where i can search in that map for a specific key and return the wanted value. although i was not able to do that. I took a deep look on your web app examples like the gueesmynumber example and i see that you are use a js post function and post the data you want like this:

B4X:
$("#btnGuess").click(function(){
            $.post("guess", "number=" + txtNumber.value,
                function(data) {
                    $("#result").html(data);
                    $("#txtNumber").focus();
                    $("#txtNumber").select();
                }
           
            );
        });

the problem in my scenario is that i am creating the elements AFTER the page was loaded and like this i have no access to those elements with the JQueryElement object of b4j or using the js code above. besides that in node.js i use the form element and a submit button to submit the request to the server and then i use a npm package BodyBuilder where i can retrieve for example the name="" value (user, pass) i have setted in the input element.

B4X:
 <form>
        <img class="logo" src="images/logo.png" alt="" width="90" height="90">
        <h1 class="h3 mb-3 fw-normal">Login to LiveTv+</h1>

        <input id="username" type="text" class="form-control top" name="user" placeholder="Username" required autofocus>
        <input id= "password" type="password" class="form-control middle" name="pass" placeholder="Password" required>

        <button id="loginbtn" class="w-100 btn btn-lg btn-primary signupbtn" type="button">Login!</button>
        <p class="mb-3 text-muted copyright">&copy; Sagital</p>
      </form>

if the html elements are present in the HTML code then everything works fine only if i create the elements on the fly i have no access to them ONLY if i would use some js code to do that. so i decided to use an event handler instead and catch the request.

what do you recommend to do if I want to receive HTML elements data after creating them on the fly with b4j?

thanx
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
i agree with you, it would be great to retrieve a map will keys: values where i can search in that map for a specific key and return the wanted value
I don't understand. As I wrote there is never a good reason to use GetKeyAt.
Just call req.GetParameter(key here)

If you don't know the key then use:
B4X:
For Each k As String In Map.Keys
 
Next

JQueryElement is not relevant here as this is not a WebSocket handler.
 
Upvote 0
Top