Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Class error : java.io.IOException: The pipe is being closed

Tags:

java

pipe

We are intermittently getting "java.io.IOException: The pipe is being closed" with below code. There is very intermittent in nature. Any advice? I tried to replicate this and when i disconnect my machine from network then i am able to get this error. This class read and write information after Siebel CRM session is open.

Here with Java class code.

   private Process _process;
   private OutputStream _processOut;
   private ByteArrayOutputStream _sessionOutput;
....
   _processOut = _process.getOutputStream();
   _sessionOutput = new ByteArrayOutputStream();
....
 public void writeCommand(String command)
   throws IOException
   {
      _processOut.write(command.getBytes());
      _processOut.flush();
      _sessionOutput.write(command.getBytes());

   }

Here with Actual error:

java.io.IOException: The pipe is being closed
    at java.io.FileOutputStream.writeBytes(Native Method)
    at java.io.FileOutputStream.write(FileOutputStream.java:260)
    at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:65)
    at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:123)
    at mySession.writeCommand(mySession.java:169)
like image 286
sanjay Avatar asked Feb 17 '11 07:02

sanjay


People also ask

How do I fix Java IO IOException broken pipe?

io. IOException: Broken pipe changing the value will help until the root cause (60s should be enough) can be fixed. Show activity on this post. 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.

What is IOException in java?

IOException is the base class for exceptions thrown while accessing information using streams, files and directories. The Base Class Library includes the following types, each of which is a derived class of IOException : DirectoryNotFoundException.

What causes Java IO IOException?

IOException is thrown when an error occurred during an input-output operation. That can be reading/writing to a file, a stream (of any type), a network connection, connection with a queue, a database etc, pretty much anything that has to do with data transfer from your software to an external medium.


2 Answers

What is happening is that the external process you are trying to write to has closed the pipe connected to its standard input stream. It may have just exited.

Try to read and print the processes standard output and standard error to see if they give an explanation as to what is going on.

like image 111
Stephen C Avatar answered Oct 13 '22 01:10

Stephen C


Well it is the case when you have closed the streams and even after that you are trying to write data to streams...

I guess a single stream is handled in 2 threads at where one thread might have closed the stream (may be programatically or by some exception in your stream closing finally block). and the other thread is not notified and trying to write on that stream.

like image 38
Rohit Mandiwal Avatar answered Oct 13 '22 01:10

Rohit Mandiwal