我使用 Jetty HttpClient 发送 POST 请求,其正文约为几 MB。我希望 Jetty 尽快开始流式传输请求,所以我使用setRequestContentSource方法。
问题是,当我使用任何带有 available() 方法的输入流返回相对较小的值(如 4096)时,Jetty 有时会崩溃并出现以下错误:
org.eclipse.jetty.io.EofException
at org.eclipse.jetty.http.HttpGenerator.flushBuffer(HttpGenerator.java:911)
at org.eclipse.jetty.client.HttpConnection.handle(HttpConnection.java:241)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:520)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:40)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:528)
at java.lang.Thread.run(Thread.java:680)
Caused by:
java.io.IOException: Broken pipe
at sun.nio.ch.FileDispatcher.write0(Native Method)
at sun.nio.ch.SocketDispatcher.write(SocketDispatcher.java:29)
at sun.nio.ch.IOUtil.writeFromNativeBuffer(IOUtil.java:100)
at sun.nio.ch.IOUtil.write(IOUtil.java:71)
at sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:334)
at org.eclipse.jetty.io.nio.ChannelEndPoint.flush(ChannelEndPoint.java:195)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint.flush(SelectChannelEndPoint.java:285)
at org.eclipse.jetty.io.nio.ChannelEndPoint.flush(ChannelEndPoint.java:316)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint.flush(SelectChannelEndPoint.java:267)
at org.eclipse.jetty.http.HttpGenerator.flushBuffer(HttpGenerator.java:846)
at org.eclipse.jetty.client.HttpConnection.handle(HttpConnection.java:241)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:520)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:40)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:528)
at java.lang.Thread.run(Thread.java:680)
这是不确定的,似乎将 Thread.sleep(10) 放在流的 read() 方法中可以解决问题。使用管道流时也可以修复此错误。这三件事让我觉得这是某种竞赛条件。
我想这是 Jetty 中的错误,但我想确定在这种情况下我是否没有做任何奇怪的事情。