简体   繁体   English

java.io.IOException: 管道损坏

[英]java.io.IOException: Broken pipe

We are currently migrating a legacy application to Jetty.我们目前正在将遗留应用程序迁移到 Jetty。 And I have somehow an exception regarding a broken pipe.不知何故,我有一个关于破损管道的例外。

  • Java 6爪哇 6
  • Jetty 8.1.8码头 8.1.8
  • Spring 3.2.0春天 3.2.0

I am trying to migrate a Glassfish web application to Jetty.我正在尝试将 Glassfish Web 应用程序迁移到 Jetty。 In our testing environment we are using a load balancer and everything is working fine.在我们的测试环境中,我们使用了负载均衡器,一切正常。 Our clients are working without any problem.我们的客户工作没有任何问题。

WARN  [2013-04-03 13:34:28,963] com.myapp.bbb.config.MvcDefaultConfig$1: Handler execution resulted in exception
! org.eclipse.jetty.io.EofException: null
! at org.eclipse.jetty.http.HttpGenerator.flushBuffer(HttpGenerator.java:914)
! at org.eclipse.jetty.http.HttpGenerator.complete(HttpGenerator.java:798)
! at org.eclipse.jetty.server.AbstractHttpConnection.completeResponse(AbstractHttpConnection.java:642)
! at org.eclipse.jetty.server.Response.complete(Response.java:1234)
! at org.eclipse.jetty.server.Response.sendError(Response.java:404)
! at org.eclipse.jetty.server.Response.sendError(Response.java:416)
! at org.springframework.web.servlet.DispatcherServlet.noHandlerFound(DispatcherServlet.java:1111)
! at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:898)
! at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
! at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:915)
! at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:811)
! at javax.servlet.http.HttpServlet.service(HttpServlet.java:735)
! at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:796)
! at javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
! at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:669)
! at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1336)
! at com.magnetdigital.maggy.dropwizard.head2get.Head2GetFilter.doFilter(Head2GetFilter.java:22)
! at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1307)
! at com.yammer.dropwizard.servlets.ThreadNameFilter.doFilter(ThreadNameFilter.java:29)
! at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1307)
! at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:453)
! at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:229)
! at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1072)
! at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:382)
! at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:193)
! at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1006)
! at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)
! at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
! at com.yammer.metrics.jetty.InstrumentedHandler.handle(InstrumentedHandler.java:200)
! at org.eclipse.jetty.server.handler.GzipHandler.handle(GzipHandler.java:275)
! at com.yammer.dropwizard.jetty.BiDiGzipHandler.handle(BiDiGzipHandler.java:123)
! at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:154)
! at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
! at org.eclipse.jetty.server.Server.handle(Server.java:365)
! at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:485)
! at org.eclipse.jetty.server.BlockingHttpConnection.handleRequest(BlockingHttpConnection.java:53)
! at org.eclipse.jetty.server.AbstractHttpConnection.headerComplete(AbstractHttpConnection.java:926)
! at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete(AbstractHttpConnection.java:988)
! at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:635)
! at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235)
! at org.eclipse.jetty.server.BlockingHttpConnection.handle(BlockingHttpConnection.java:72)
! at org.eclipse.jetty.server.nio.BlockingChannelConnector$BlockingChannelEndPoint.run(BlockingChannelConnector.java:298)
! at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
! at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
! at java.lang.Thread.run(Thread.java:662)
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:69)
! at sun.nio.ch.IOUtil.write(IOUtil.java:26)
! at sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:334)
! at org.eclipse.jetty.io.nio.ChannelEndPoint.flush(ChannelEndPoint.java:293)
! at org.eclipse.jetty.server.nio.BlockingChannelConnector$BlockingChannelEndPoint.flush(BlockingChannelConnector.java:253)
! at org.eclipse.jetty.http.HttpGenerator.flushBuffer(HttpGenerator.java:850)
!... 44 common frames omitted

When I check the stacktrace I have seen this exceptions are triggered by always a 404 request.当我检查堆栈跟踪时,我看到这个异常总是由 404 请求触发。

org.springframework.web.servlet.DispatcherServlet.noHandlerFound(DispatcherServlet.java:1111) org.springframework.web.servlet.DispatcherServlet.noHandlerFound(DispatcherServlet.java:1111)

  • Why am I having this exception?为什么我有这个例外?
  • How can I reproduce this exception at my machine locally?如何在本地机器上重现此异常?

The most common reason I've had for a "broken pipe" is that one machine (of a pair communicating via socket) has shut down its end of the socket before communication was complete.我对“管道损坏”的最常见原因是(一对通过套接字通信的)机器在通信完成之前关闭了它的套接字端。 About half of those were because the program communicating on that socket had terminated.其中大约一半是因为在该套接字上通信的程序已终止。

If the program sending bytes sends them out and immediately shuts down the socket or terminates itself, it is possible for the socket to cease functioning before the bytes have been transmitted and read.如果发送字节的程序将它们发送出去并立即关闭套接字或自行终止,则套接字有可能在字节被传输和读取之前停止运行。

Try putting pauses anywhere you are shutting down the socket and before you allow the program to terminate to see if that helps.尝试在您关闭套接字的任何地方以及允许程序终止之前暂停以查看是否有帮助。

FYI: "pipe" and "socket" are terms that get used interchangeably sometimes.仅供参考:“管道”和“套接字”是有时可以互换使用的术语。

I agree with @arcy, the problem is on client side, on my case it was because of nginx, let me elaborate I am using nginx as the frontend (so I can distribute load, ssl, etc ...) and using proxy_pass http://127.0.0.1:8080 to forward the appropiate requests to tomcat.我同意@arcy,问题出在客户端,在我的情况下是因为 nginx,让我详细说明我使用 nginx 作为前端(因此我可以分发负载、ssl 等...)并使用proxy_pass http://127.0.0.1:8080将适当的请求转发给 tomcat。

There is a default value for the nginx variable proxy_read_timeout of 60s that should be enough, but on some peak moments my setup would error with the java.io.IOException: Broken pipe changing the value will help until the root cause (60s should be enough) can be fixed. nginx 变量proxy_read_timeout有一个 60 秒的默认值应该就足够了,但是在某些高峰时刻,我的设置会出现java.io.IOException: Broken pipe更改值将有所帮助,直到根本原因(60 秒应该足够了) ) 可以修复。

NOTE: I made a new answer so I could expand a bit more with my case (it was the only mention I found about this error on internet after looking quite a lot)注意:我做了一个新的答案,所以我可以用我的案例进行更多的扩展(这是我在网上找到了很多关于这个错误的唯一提及)

Basically, what is happening is that your user is either closing the browser tab, or is navigating away to a different page, before communication was complete.基本上,发生的情况是您的用户在通信完成之前关闭了浏览器选项卡,或者导航到不同的页面。 Your webserver (Jetty) generates this exception because it is unable to send the remaining bytes.您的网络服务器 (Jetty) 会生成此异常,因为它无法发送剩余字节。

org.eclipse.jetty.io.EofException: null
! at org.eclipse.jetty.http.HttpGenerator.flushBuffer(HttpGenerator.java:914)
! at org.eclipse.jetty.http.HttpGenerator.complete(HttpGenerator.java:798)
! at org.eclipse.jetty.server.AbstractHttpConnection.completeResponse(AbstractHttpConnection.java:642)
! 

This is not an error on your application logic side.这不是您的应用程序逻辑方面的错误。 This is simply due to user behavior.这仅仅是由于用户行为。 There is nothing wrong in your code per se.您的代码本身没有任何问题。

There are two things you may be able to do:您可以做两件事:

  1. Ignore this specific exception so that you don't log it.忽略这个特定的异常,这样你就不会记录它。
  2. Make your code more efficient/packed so that it transmits less data.使您的代码更高效/打包,以便传输更少的数据。 (Not always an option!) (并不总是一种选择!)

Error message suggests that the client has closed the connection while the server is still trying to write out a response.错误消息表明客户端已关闭连接,而服务器仍在尝试写出响应。

Refer to this link for more details:有关更多详细信息,请参阅此链接:

https://markhneedham.com/blog/2014/01/27/neo4j-org-eclipse-jetty-io-eofexception-caused-by-java-io-ioexception-broken-pipe/ https://markhneedham.com/blog/2014/01/27/neo4j-org-eclipse-jetty-io-eofexception-caused-by-java-io-ioexception-broken-pipe/

您可能没有设置输出文件。

增加 response.getBufferSize() 获取缓冲区大小并与您要传输的字节进行比较!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 PipedInputStream - 如何避免“java.io.IOException:Pipe broken” - PipedInputStream - How to avoid “java.io.IOException: Pipe broken” 避免日志充满 java.io.IOException: Broken pipe - Avoid logs full of java.io.IOException: Broken pipe 具有拍摄意图的Android FileProvider给出java.io.IOException:写入失败:EPIPE(管道损坏) - Android FileProvider with photo take intent gives a java.io.IOException: write failed: EPIPE (Broken pipe) 如何修复 java.io.IOException: write failed: EPIPE (Broken pipe) 当我扎根时? - How do I fix java.io.IOException: write failed: EPIPE (Broken pipe) when I am rooted? 提交响应 java.io.IOException 时出错:sun.nio.ch.FileDispatcher.write0(Native Method) 处的管道损坏 - Error commiting response java.io.IOException: Broken pipe at sun.nio.ch.FileDispatcher.write0(Native Method) java.io.IOException java - java.io.IOException java MapReduce 中的 java.io.IOException - java.io.IOException in MapReduce Why did I get “Error commiting response java.io.IOException: Broken pipe at sun.nio.ch.FileDispatcher.write0(Native Method)” with SSL - Why did I get “Error commiting response java.io.IOException: Broken pipe at sun.nio.ch.FileDispatcher.write0(Native Method)” with SSL com.jcraft.jsch.JSchException:java.io.IOException:通道已损坏 - com.jcraft.jsch.JSchException: java.io.IOException: channel is broken java.io.IOException:Java中的权限被拒绝 - java.io.IOException: Permission denied in Java
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM