31

what is the meaning of broken pipe exception and when it will come?

Audrius Meškauskas
  • 20,936
  • 12
  • 75
  • 93
varakumar.pjd
  • 713
  • 2
  • 8
  • 13

3 Answers3

72

A pipe is a data stream, typically data being read from a file or from a network socket. A broken pipe occurs when this pipe is suddenly closed from the other end. For a flie, this could be if the file is mounted on a disc or a remote network which has become disconnected. For a network socket, it could be if the network gets unplugged or the process on the other end crashes.

In Java, there is no BrokenPipeException specifically. This type of error will be found wrapped in a different exception, such as a SocketException or IOException.

Erick Robertson
  • 32,125
  • 13
  • 69
  • 98
  • Nice explanation , yes , it is wrapped in IOException ,but with this clear message as "Broken pipe" , In log we will get something like this : Caused by: java.io.IOException: Broken pipe – Asraful Feb 09 '17 at 11:57
  • @xyz_scala if this is happening repeatedly, then it's possible one end of the software is closing the socket and you're getting it on the other end, or you're having a hardware failure and you're getting it on both ends – Erick Robertson May 15 '19 at 12:41
  • Broken pipe happens only when you write to a connection that was closed by the other end. When you read from a connection that was closed by the other end, you get end-of-file. – Karsten Spang Nov 27 '20 at 15:56
6

Pipe is basically a communication channel between two processes. So one process writes to the pipe while the other reads from it. A broken pipe exception typically means that one process is attempting to read or writ data from a pipe, where as the process on the other end of the pipe has died/been killed.

Rohith
  • 2,043
  • 1
  • 17
  • 42
0

I think you are using Java.net ?

If you closed the connection, then you need to open a new socket before you can send more data.

or your connections is been rejected

Arrabi
  • 3,718
  • 4
  • 26
  • 38
  • 1
    If he had closed his own connection he would have got 'socket closed'. If his connection attempt had failed he wouldn't have even got a `Socket.` In neither case would he have got 'broken pipe'. There is no evidence in the question as to whether or not he is using `java.net.` – user207421 Sep 20 '15 at 09:35