-
Notifications
You must be signed in to change notification settings - Fork 446
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CustomSearch: NoHttpResponseException exception if interval between requests is 240+ seconds #1791
Comments
Thanks for reporting this and for the small repro. I'll take a look when I get a bit of time. Can you explain this part to me?
What did you mean by |
@lqiu96 thanks for taking a look. Directly = using apache's http client, without google http transport wrapper.
|
Hi @zhemaituk. I took look at the samples you provided and wasn't able to find a root cause yet -- I was able to reproduce. I took a look at I'ved played around with using
which seems like it may help with resolving this test. Though, do let me know otherwise. I'll need to take another look later today and dig deeper. |
Yeah, I switched to |
Apologies, I haven't had much time to look into this recently. This is on my TODO list to investigate, but do let me know if you are facing any pressing/ blocking issues! From my suspicions above, I think it should resolve your issues. I'm not too familiar with this library and I need a bit more time to give you the proof 😄 |
Hi, I've done a bit more digging and I have some thoughts. I'm not an expert with the Apache Http Library so I can only provide my guesses from my understanding -- I've added logging from some debugging below: Google Client:
Result: Fail
Result: Pass
Result: Pass Apache Client:
Result: Pass From the logs above, it looks like the Apache Http Client has some logic internally to release/ close the connection. Given that there doesn't seem to be any The Google Client seems to want to keep the connection alive and the test with manually closing the connection works to get the result the second time. Because this seems to only happen after 240+ seconds, I suspect that the connection is closed from the server side after ~4 minutes (possibly some server side configuration). The test with 5 minutes is going to try with the already established connection (though no longer valid) and fails to get a valid response. I think the best bet is to either use a PooledHttpClientConnectionManager (allowing more than 1 connection), manually specify your keep-alive strategy to close a connection if no response after a certain amount of time (https://www.baeldung.com/httpclient-connection-management), or manually close the connection via:
|
@lqiu96 are you able to reproduce the issue with Apache http client alone? If we have a valid usage example which fails - we can log a bug against http-client itself. |
I think I found a way to reproduce with Apache Client.
So maybe closing the response instead of closing content InputStream would do? |
I wasn't able to reproduce the issue with the earlier code above (even with some testing and tinkering). But, I was able to in the latest one where you don't close put the CloseableHttpResponse in try-with resources.
Yeah, I believe that is the case. From my understanding, there is a difference between releasing and closing the connection. Releasing the connection allows it to re-enter the connection pool (i.e. in the case of From this helpful Baeldung article: https://www.baeldung.com/httpclient-connection-management#re-use I think we can mimic the connection close with something like this: i.e.
Or any of the other suggestions above. Let me know you thoughts. |
Concluding, it sounds like a bug in BasicHttpClientConnectionManager itself. Running the same Apache Client code with two different connection managers:
5 seconds delay (connection is re-used):
5 minutes delay (connection is re-established):
With I would say the most suitable workaround is to use |
Logged a ticket for the http client project: https://issues.apache.org/jira/browse/HTTPCLIENT-2255 |
I think this would work for now and the logs from your comment above do seem to support this. I wasn't expecting this to work:
I would have thought that this would also run into the same issue with the Google Http Client. Given that there is only one connection per route and the connection wasn't closed via some sort of I do see this in the docs which may explain the behavior (or I may be missing something...): vs.
I think we've reached the same conclusion now. Thanks for submitting the issue -- Let's see what the Apache HttpClient folks have to say. |
We got the response there - it's not reproducible with httpclient5 (I double checked as well), and won't be fixed for 4.x. |
Thanks for the update @zhemaituk. I'll close this ticket and create a new issue to start a discussion regarding possibly migrating to Apache HttpClient v5. |
Environment details
OS type and version: macOS 13.0.1
Java version: jdk1.8.0_251.jdk
google-http-client-apache-v2-1.42.3
Steps to reproduce
ApacheHttpTransport
Code example
Stack trace
Any additional information below
Same error when using google-api-services-customsearch-v1-rev20210918-2.0.0
CustomSearchAPI
.No error, all completes fine, if using apache's
CloseableHttpClient
directly to make the same requests.The text was updated successfully, but these errors were encountered: