java
io_error
ai_generated
true
java.io.IOException: Broken pipe
ID: java/broken-pipe
80%Fix Rate
85%Confidence
80Evidence
2023-01-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 17 | active | — | — | — |
Root Cause
Broken pipe occurs when the application writes to a socket or pipe whose reading end has already been closed by the remote peer. Common in HTTP servers when clients disconnect before the response is fully sent.
genericWorkarounds
-
88% success Catch the IOException gracefully and log it at a lower severity, since client disconnections are often expected
1. Wrap the write operation in a try-catch for IOException. 2. Check if the message contains 'Broken pipe'. 3. Log at WARN or DEBUG level rather than ERROR, since clients disconnecting mid-response is normal behavior (e.g., user navigates away). 4. Clean up the connection resources in the finally block.
-
82% success Implement connection keep-alive probes and check connection state before writing large responses
1. Enable TCP keep-alive on the socket: socket.setKeepAlive(true). 2. For large responses, periodically flush and check for write errors early rather than buffering the entire response. 3. In HTTP servers, check if the client connection is still alive before beginning expensive response generation.
Dead Ends
Common approaches that don't work:
-
Increasing socket timeout values to prevent the broken pipe
75% fail
Broken pipe is not a timeout issue — the remote end has actively closed the connection. Increasing timeouts does not prevent the peer from disconnecting and only delays detection of the problem.
-
Retrying the write operation immediately after the broken pipe
90% fail
Once the pipe is broken, the connection is dead. Retrying writes on the same socket will produce the same IOException. A new connection must be established before retrying.
Error Chain
Preceded by:
Frequently confused with: