title: What is the reason for Broken Pipe on Unix Domain Sockets?
body: <p>I have a server application which received requests and forwards them on a Unix Domain Socket. This works perfectly under reasonable usage but when I am doing some load tests with a few thousand requests I am getting a Broken Pipe error.</p>
  
  <p>I am using Java 7 with <a href="http://code.google.com/p/junixsocket/" rel="noreferrer">junixsocket</a> to send the requests. I have lots of concurrent requests, but I have a thread pool of 20 workers which is writing to the unix domain socket, so there is no issue of too many concurrent open connections.</p>
  
  <p>For each request I am opening, sending and closing the connection with the Unix Domain Socket.</p>
  
  <p>What is the reason that could cause a Broken Pipe on Unix Domain Sockets? </p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>Putting a code sample if required:</p>
  
  <pre><code>byte[] mydata = new byte[1024];
  //fill the data with bytes ...
  
  AFUNIXSocketAddress socketAddress = new AFUNIXSocketAddress(new File("/tmp/my.sock"));
  Socket socket = AFUNIXSocket.connectTo(socketAddress);
  OutputStream out = new BufferedOutputStream(socket.getOutputStream());
  InputStream in = new BufferedInputStream(socket.getInputStream()));
  
  out.write(mydata);
  out.flush();  //The Broken Pipe occurs here, but only after a few thousand times
  
  //read the response back...
  
  out.close();
  in.close();
  socket.close();
  </code></pre>
  
  <p>I have a thread pool of 20 workers, and they are doing the above concurrently (so up to 20 concurrent connections to the same Unix Domain Socket), with each one opening, sending and closing. This works fine for a load test of a burst of 10,000 requests but when I put a few thousand more I suddenly get this error, so I am wondering whether its coming from some OS limit.</p>
  
  <p>Keep in mind that this is a Unix Domain Socket, not a network TCP socket.</p>