1
votes

I am using jetty-9.

My configuration is: connector.setIdleTimeout(20000).

My jetty handler is:

public void handle(String target, Request baseRequest,
        HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
    // TODO Auto-generated method stub


    AsyncContext ctx = request.startAsync();
    ctx.setTimeout(0);

     XXXXX...(Other process with ctx)
}

But after 30s, jetty just print logs like:

DEBUG [org.eclipse.jetty.io.WriteFlusher]:  ignored: WriteFlusher@7cc4b130{IDLE} java.util.concurrent.TimeoutException: Idle timeout expired: 20004/20000 ms

DEBUG [org.eclipse.jetty.io.AbstractEndPoint]:  Ignored idle endpoint SelectChannelEndPoint@387b2c97{/127.0.0.1:59889<->8088,Open,in,out,-,-,20005/20000,HttpConnection}{io=0/0,kio=0,kro=1}

the connection isn't closed but active.And i still can use "ctx" to send the rsp to the client.
Anyone can help me?

1
What specific version of Jetty 9? - Joakim Erdfelt
Thanks ! Jetty version is 9.3.5.v20151012. - carydu

1 Answers

3
votes

The behaviour here will depend on what the XXXX handling does. If the XXXX handling is still running, then the AsyncContext timeout will not fire, as it is only activated once the thread dispatched to the servlet returns to the container.

So if XXX is doing lots of stuff or sleeping, then that timeout is not going to work.

Also the javadoc says that a timeout of 0 or less means no timeout! So try with timeout(1) or some small value.

edit: Furthermore, once a servlet has been dispatched, the connectors idle timeout only applies to blocking IO operations. So if you are not reading or writing with blocking API then the connectors idle timeout also does not apply.

The servlet spec basically trusts servlets to never go infinite - the container is not allowed to impose an idle timeout on the processing time. A long time ago, Jetty used to interrupt servlets in this circumstance, but we were informed in no uncertain terms that it was contrary to the specification.