Henry Tung created HTTPCLIENT-2195:
--------------------------------------

             Summary: [regression] Logic error in proxy connection error 
handling in ConnectExec.createTunnelToTarget
                 Key: HTTPCLIENT-2195
                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-2195
             Project: HttpComponents HttpClient
          Issue Type: Bug
          Components: HttpClient (classic)
    Affects Versions: 5.1.2
            Reporter: Henry Tung


This moved block seems suspect:

[https://github.com/apache/httpcomponents-client/commit/90d89af98e6cb9e4437d178acf084259607a20c3#diff-81d61e0ba1700fd4dcfb00bf8a8943beec35d825546d1a6b8e35fc5796902656R230]

It always consumes the response and/or disconnects the connection (code 
apparently moved from proxy auth challenge retry handling?), but the error 
handling block below (code != SC_OK) attempts to read the response, triggering 
a very not-informative StreamClosedException (and losing the original, useful 
error).

Not entirely clear what the moved block actually does or is intended to do, but 
it seems like the response content should be saved for later use by 
error-handling or only conditionally-consumed later (when the response is known 
to be successful).

Example stacktrace from a proxy tunneling error:
{noformat}
Caused by: org.apache.hc.core5.http.StreamClosedException: Stream already closed
    at 
org.apache.hc.core5.http.impl.io.ContentLengthInputStream.read(ContentLengthInputStream.java:162)
    at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:284)
    at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:326)
    at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:178)
    at java.io.InputStreamReader.read(InputStreamReader.java:181)
    at java.io.Reader.read(Reader.java:229)
    at 
org.apache.hc.core5.http.io.entity.EntityUtils.toCharArrayBuffer(EntityUtils.java:178)
    at 
org.apache.hc.core5.http.io.entity.EntityUtils.toString(EntityUtils.java:221)
    at 
org.apache.hc.core5.http.io.entity.EntityUtils.toString(EntityUtils.java:361)
    at 
org.apache.hc.core5.http.io.entity.EntityUtils.toString(EntityUtils.java:341)
    at 
org.apache.hc.client5.http.impl.classic.ConnectExec.createTunnelToTarget(ConnectExec.java:258)
    at 
org.apache.hc.client5.http.impl.classic.ConnectExec.execute(ConnectExec.java:145)
    at 
org.apache.hc.client5.http.impl.classic.ExecChainElement.execute(ExecChainElement.java:51)
    at 
org.apache.hc.client5.http.impl.classic.ExecChainElement$1.proceed(ExecChainElement.java:57)
    at 
org.apache.hc.client5.http.impl.classic.ProtocolExec.execute(ProtocolExec.java:175)
    at 
org.apache.hc.client5.http.impl.classic.ExecChainElement.execute(ExecChainElement.java:51)
    at 
org.apache.hc.client5.http.impl.classic.ExecChainElement$1.proceed(ExecChainElement.java:57)
    at 
org.apache.hc.client5.http.impl.classic.RedirectExec.execute(RedirectExec.java:115)
    at 
org.apache.hc.client5.http.impl.classic.ExecChainElement.execute(ExecChainElement.java:51)
    at 
org.apache.hc.client5.http.impl.classic.InternalHttpClient.doExecute(InternalHttpClient.java:170)
    at 
org.apache.hc.client5.http.impl.classic.CloseableHttpClient.execute(CloseableHttpClient.java:75)
    at 
org.apache.hc.client5.http.impl.classic.CloseableHttpClient.execute(CloseableHttpClient.java:89){noformat}



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

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

Reply via email to