Java broken pipe process

java.io.IOException: Broken pipe

I am trying to migrate a Glassfish web application to 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.

  • Why am I having this exception?
  • How can I reproduce this exception at my machine locally?

Источник

Java NIO: What does IOException: Broken pipe mean? [duplicate]

For some of my Java NIO connections, when I have a SocketChannel.write(ByteBuffer) call, it throws an IOException : «Broken pipe». What causes a «broken pipe», and, more importantly, is it possible to recover from that state? If it cannot be recovered, it seems this would be a good sign that an irreversible problem has occurred and that I should simply close this socket connection. Is that a reasonable assumption? Is there ever a time when this IOException would occur while the socket connection is still being properly connected in the first place (rather than a working connection that failed at some point)? On a side note, is it wise to always call SocketChannel.isConnected() before attempting a SocketChannel.write() , and if so, can I also assume that the connection is «broken» and should be closed if both SocketChannel.isConnected() and SocketChannel.isConnectionPending() are both false ? Thanks!

Читайте также:  Parse any date format java

4 Answers 4

What causes a «broken pipe», and more importantly, is it possible to recover from that state?

It is caused by something causing the connection to close. (It is not your application that closed the connection: that would have resulted in a different exception.)

It is not possible to recover the connection. You need to open a new one.

If it cannot be recovered, it seems this would be a good sign that an irreversible problem has occurred and that I should simply close this socket connection. Is that a reasonable assumption?

Yes it is. Once you’ve received that exception, the socket won’t ever work again. Closing it is is the only sensible thing to do.

Is there ever a time when this IOException would occur while the socket connection is still being properly connected in the first place (rather than a working connection that failed at some point)?

No. (Or at least, not without subverting proper behavior of the OS’es network stack, the JVM and/or your application.)

Is it wise to always call SocketChannel.isConnected() before attempting a SocketChannel.write() .

In general, it is a bad idea to call r.isXYZ() before some call that uses the (external) resource r . There is a small chance that the state of the resource will change between the two calls. It is a better idea to do the action, catch the IOException (or whatever) resulting from the failed action and take whatever remedial action is required.

In this particular case, calling isConnected() is pointless. The method is defined to return true if the socket was connected at some point in the past. It does not tell you if the connection is still live. The only way to determine if the connection is still alive is to attempt to use it; e.g. do a read or write.

Читайте также:  Php запятая в цифрах

Источник

PipedInputStream — How to avoid «java.io.IOException: Pipe broken»

I have two threads. One of them writes to PipedOutputStream, another one reads from corresponding PipedInputStream. Background is that one thread is downloading some data from remote server and multiplexes it to several other threads through piped streams. The problem is that sometimes (especially when downloading large (>50Mb) files) I get java.io.IOException: Pipe broken when trying to read from PipedInputStream.
Javadoc says that A pipe is said to be broken if a thread that was providing data bytes to the connected piped output stream is no longer alive.
It is true, my writing thread really dies after writing all his data to PipedOutputStream. Any solutions? How can I prevent PipedInputStream from throwing this exception? I want to be able to read all data that was written to PipedOutputStream even if writing thread finished his work. (If anybody knows how to keep writing thread alive until all data will be read, this solution is also acceptable).

4 Answers 4

Use a java.util.concurrent.CountDownLatch, and do not end the first thread before the second one has signaled that is has finished reading from the pipe.

Update: quick and dirty code to illustrate my comment below

 final PipedInputStream pin = getInputStream(); final PipedOutputStream pout = getOutputStream(); final CountDownLatch latch = new CountDownLatch(1); InputStream in = new InputStream() < @Override public int read() throws IOException < return pin.read(); >@Override public void close() throws IOException < super.close(); latch.countDown(); >>; OutputStream out = new OutputStream() < @Override public void write(int b) throws IOException < pout.write(b); >@Override public void close() throws IOException < while(latch.getCount()!=0) < try < latch.await(); >catch (InterruptedException e) < //too bad >> super.close(); > >; //give the streams to your threads, they don't know a latch ever existed threadOne.feed(in); threadTwo.feed(out); 

Источник

Читайте также:  Password reset form html

Java Socket — Broken pipe error

I am trying to send int value, long value, long array and 2d double array via socket from the Client to the Server. I successfully sent int, long values and long array, however when it comes to the double array (output.writeObject(server_ind); — see Client Side code below), I am getting the following error: ERROR:

java.net.SocketException: Broken pipe at java.net.SocketOutputStream.socketWrite0(Native Method) at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:113) at java.net.SocketOutputStream.write(SocketOutputStream.java:159) at java.io.ObjectOutputStream$BlockDataOutputStream.drain(ObjectOutputStream.java:1876) at java.io.ObjectOutputStream$BlockDataOutputStream.writeByte(ObjectOutputStream.java:1914) at java.io.ObjectOutputStream.writeFatalException(ObjectOutputStream.java:1575) at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:350) at clientSide.ClientSocket.connectionProtocol(ClientSocket.java:36) at clientSide.clientMain.main(clientMain.java:97) 
 ObjectOutputStream output = new ObjectOutputStream(socket.getOutputStream()); output.writeObject(num_doc); //int value output.flush(); output.writeObject(num); //long value output.flush(); output.writeObject(queryTDs); //long[] array output.flush(); output.writeObject(server_ind); //double[][] output.flush(); 
 input = new ObjectInputStream(clientSocket.getInputStream()); num_doc = input.readInt(); num = input.readLong(); TDs = (long[]) input.readObject(); server_ind = (double[][]) input.readObject(); output = new ObjectOutputStream(clientSocket.getOutputStream()); output.writeObject("Received"); 

Источник

Оцените статью