Details
-
Bug
-
Status: Resolved
-
Major
-
Resolution: Fixed
-
4.5.9
-
None
Description
Summary
If a service responds with an error (e.g. 4xx) and closes the connection while the Apache HTTP client is sending a request, the Apache HTTP client will raise a Broken Pipe (Write Failed) exception instead of returning the 4xx response as a response to the caller.
RFC 7230 documents this as a SHOULD, not a MUST: https://tools.ietf.org/html/rfc7230#section-6.5:]:
A client sending a message body SHOULD monitor the network connection
for an error response while it is transmitting the request. If the
client sees a response that indicates the server does not wish to
receive the message body and is closing the connection, the client
SHOULD immediately cease transmitting the body and close its side of
the connection.
Other HTTP Clients
JDK 11's HttpClient seems to handle this edge case gracefully.
Reproduction
I'm currently working on a self-contained reproduction case for this issue, but wanted to cut it before that's done in case this is a known issue that I just haven't been able to find with a search.
Stack Trace
java.net.SocketException: Broken pipe (Write failed) at java.net.SocketOutputStream.socketWrite0(Native Method) ~[?:1.8.0_231] at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:111) ~[?:1.8.0_231] at java.net.SocketOutputStream.write(SocketOutputStream.java:155) ~[?:1.8.0_231] at sun.security.ssl.OutputRecord.writeBuffer(OutputRecord.java:431) ~[?:1.8.0_231] at sun.security.ssl.OutputRecord.write(OutputRecord.java:417) ~[?:1.8.0_231] at sun.security.ssl.SSLSocketImpl.writeRecordInternal(SSLSocketImpl.java:879) ~[?:1.8.0_231] at sun.security.ssl.SSLSocketImpl.writeRecord(SSLSocketImpl.java:850) ~[?:1.8.0_231] at sun.security.ssl.AppOutputStream.write(AppOutputStream.java:123) ~[?:1.8.0_231] at org.apache.http.impl.conn.LoggingOutputStream.write(LoggingOutputStream.java:74) ~[Apache-HttpComponents-HttpClient-4.5.x.jar:?] at org.apache.http.impl.io.SessionOutputBufferImpl.streamWrite(SessionOutputBufferImpl.java:124) ~[Apache-HttpComponents-HttpCore-4.4.x.jar:?] at org.apache.http.impl.io.SessionOutputBufferImpl.flushBuffer(SessionOutputBufferImpl.java:136) ~[Apache-HttpComponents-HttpCore-4.4.x.jar:?] at org.apache.http.impl.io.SessionOutputBufferImpl.write(SessionOutputBufferImpl.java:167) ~[Apache-HttpComponents-HttpCore-4.4.x.jar:?] at org.apache.http.impl.io.ChunkedOutputStream.flushCacheWithAppend(ChunkedOutputStream.java:122) ~[Apache-HttpComponents-HttpCore-4.4.x.jar:?] at org.apache.http.impl.io.ChunkedOutputStream.write(ChunkedOutputStream.java:179) ~[Apache-HttpComponents-HttpCore-4.4.x.jar:?] at org.apache.http.entity.InputStreamEntity.writeTo(InputStreamEntity.java:134) ~[Apache-HttpComponents-HttpCore-4.4.x.jar:?] at com.amazonaws.http.RepeatableInputStreamRequestEntity.writeTo(RepeatableInputStreamRequestEntity.java:160) ~[AWSJavaClientRuntime-1.11.x.jar:?] at org.apache.http.impl.DefaultBHttpClientConnection.sendRequestEntity(DefaultBHttpClientConnection.java:156) ~[Apache-HttpComponents-HttpCore-4.4.x.jar:?] at org.apache.http.impl.conn.CPoolProxy.sendRequestEntity(CPoolProxy.java:152) ~[Apache-HttpComponents-HttpClient-4.5.x.jar:?] at org.apache.http.protocol.HttpRequestExecutor.doSendRequest(HttpRequestExecutor.java:238) ~[Apache-HttpComponents-HttpCore-4.4.x.jar:?] at com.amazonaws.http.protocol.SdkHttpRequestExecutor.doSendRequest(SdkHttpRequestExecutor.java:63) ~[AWSJavaClientRuntime-1.11.x.jar:?] at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:123) ~[Apache-HttpComponents-HttpCore-4.4.x.jar:?] at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:272) ~[Apache-HttpComponents-HttpClient-4.5.x.jar:?] at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:186) ~[Apache-HttpComponents-HttpClient-4.5.x.jar:?] at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185) ~[Apache-HttpComponents-HttpClient-4.5.x.jar:?] at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83) ~[Apache-HttpComponents-HttpClient-4.5.x.jar:?] at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:56) ~[Apache-HttpComponents-HttpClient-4.5.x.jar:?]