Matthew Miller created HTTPCLIENT-2093:
------------------------------------------

             Summary: Broken pipe (Write failed) if service returns error while 
request is being sent
                 Key: HTTPCLIENT-2093
                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-2093
             Project: HttpComponents HttpClient
          Issue Type: Bug
          Components: HttpClient (classic)
    Affects Versions: 4.5.9
            Reporter: Matthew Miller


*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]:]:
{quote}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.
{quote}
*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*
{code:java}
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:?]
{code}
 

 



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to