[ 
https://issues.apache.org/jira/browse/HTTPCLIENT-2118?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17206396#comment-17206396
 ] 

Michael Lee commented on HTTPCLIENT-2118:
-----------------------------------------

Yes, problem solved after I set the period of inactivity after which a 
connection is validated to 2000 ms (the default value in 4.5.x according to 
[its source 
code|https://github.com/apache/httpcomponents-client/blob/4.5.x/httpclient/src/main/java/org/apache/http/impl/conn/PoolingHttpClientConnectionManager.java])
 while keeping other settings unchanged:
  
{code:java}
PoolingHttpClientConnectionManager connManager = new 
PoolingHttpClientConnectionManager();
connManager.setValidateAfterInactivity(TimeValue.ofMilliseconds(2000));

client = HttpClients.custom()
                .setDefaultRequestConfig(requestConfig)
                .setUserAgent(USER_AGENT)
                .setConnectionManager(connManager)
                .build();
{code}

 The javadoc of 
[PoolingHttpClientConnectionManager|https://hc.apache.org/httpcomponents-client-5.0.x/httpclient5/apidocs/org/apache/hc/client5/http/impl/io/PoolingHttpClientConnectionManager.html]
 is a bit confusing. It says:
{quote}The handling of stale connections was changed in version 4.4. 
Previously, the code would check every connection by default before re-using 
it. The code now only checks the connection if the elapsed time since the last 
use of the connection exceeds the timeout that has been set. The default 
timeout is set to 5000ms.
{quote}
To be really conservative, I think I should set it to 0 so that a connection is 
validation every time before it is reused? There is no guarantee that the 
server will honor any keep-alive time and may close a connection at any time.

> Difference in behavior between 4.5.x and 5.0.x - CloseableHttpClient returns 
> 403 after NoHttpResponseException
> --------------------------------------------------------------------------------------------------------------
>
>                 Key: HTTPCLIENT-2118
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-2118
>             Project: HttpComponents HttpClient
>          Issue Type: Bug
>          Components: HttpClient (classic), HttpClient (Windows)
>    Affects Versions: 5.0.2
>         Environment: Microsoft Windows 10 version 2004 [10.0.19041.508]
> Oracle JDK 11.0.8
>            Reporter: Michael Lee
>            Priority: Major
>         Attachments: all_except_wire.log, all_except_wire.setMaxTotal5.log, 
> all_except_wire.setMaxTotal6.log, demo.zip, headers.log, test_output.txt, 
> wireshark.pcapng
>
>
> My application reuses an instance of CloseableHttpClient to retrieve the 
> content from a list of URLs. After upgrading HttpClient from 4.5.x to 5.0.2 
> (also 5.0 and 5.0.1), it always gets a NoHttpResponseException followed by a 
> response code of 403 for a particular URL in the list.  When using 4.5.x, it 
> always gets a 200 or 304 for that particular URL.
> The behavior may be different if the order of the URLs in the list is changed.
> To illustrate the problem, I have extracted code from my application into the 
> sample Maven project attached. In the JUnit test, testHttpClient4() will get 
> either 200 or 304 for all the URLs. On the other hand, testHttpClient5() 
> always gets 403 for the last URL in the list. In this project, I 
> intentionally added a If-Modified-Since header with the value being current 
> time minus 1 minute so that we should get a 304 from most of the URLs.
> Can you investigate if this is really an obscure bug or an undocumented 
> behavior change related to how CloseableHttpClient handles redirects?
> Thanks.



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

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@hc.apache.org
For additional commands, e-mail: dev-h...@hc.apache.org

Reply via email to