Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-users] TimeoutException: Idle Ttmeout expired

Hi,

On Thu, Apr 7, 2016 at 12:52 PM, Mark Strempel <zouroboros@xxxxxxxxx> wrote:
> Hi everybody,
>
> Im trying to serve some large files (>700mb) using jetty as an embedded
> server in an java application. Currently Im receiving the following
> TimeoutException:
>
> java.util.concurrent.TimeoutException: Idle timeout expired:
> 30000/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.ac
> cess$201(ScheduledThreadPoolExecutor.java:180)
>         at
> java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.ru
> n(ScheduledThreadPoolExecutor.java:293)
>         at
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.ja
> va:1142)
>         at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.j
> ava:617)
>         at java.lang.Thread.run(Thread.java:745)
>
> (sorry for the bad formatting)
>
> This is the code where the exception is thrown:
> response.setContentLengthLong(/*length of large file*/);
> OutputStream stream = response.getOutputStream();
> InputStream inStream = new FileInputStream(/*large file*/);
> byte[] buffer = new byte[4096];
> int read;
> while((read = inStream.read(buffer)) > 0) {

Should be:

while((read = inStream.read(buffer)) >= 0) {

If, for any reason, you read 0 bytes, you are going to exit the loop
and send only part of the file.

>         stream.write(buffer, 0, read); // exception happens here
> }
> inStream.close();
> stream.flush();
> stream.close();
>
> Interestingly though this exceptions is not thrown at all requests. E.g
> if Im trying to get the file with curl everything works without any
> exception. I would be glad for any hints what the reason behind this
> exception could be.

Your client does not read the content being downloaded by the server,
so the server times out.

-- 
Simone Bordet
----
http://cometd.org
http://webtide.com
Developer advice, training, services and support
from the Jetty & CometD experts.


Back to the top