Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the NoHttpResponse failed to respond problem

2025-03-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article introduces you how to solve the NoHttpResponse failed to respond problem, the content is very detailed, interested friends can use for reference, hope to be helpful to you.

During the operation of the project, org.apache.http.NoHttpResponseException: xxxx.com:80 failed to respond reports an error, and the error occurs irregularly. The test interface with postMan and other tools is normal, and the error cannot be repeated in the project debugging, but the error will occur in the production environment.

The server is the springBoot project and the client is SpringMvc.

Analysis: there is no exception to call the interface using postMan or handwritten Test, so what is the difference with the project? Starting from the analysis of the introduced package, I found that the version of httpClient was consistent. I suddenly thought that connection pooling was enabled for the sake of performance in the project. Could it be that the server actively closed the connection, and the client did not know, but still used this link?

Verification: client establishes connection-> server manually closes connection-> client invokes interface Bingo reports an error

Conclusion: the keepAliveTimeOut of the server is inconsistent with that of the client, which causes the server to close the link before the client, but the client still uses the connection, resulting in an error report.

Resolve:

Option 1. The server sets the keepAliveTimeOut time the same as the client.

Option 2. The client configuration ConnectionKeepAliveStrategy code is as follows:

ConnectionKeepAliveStrategy strategy = new ConnectionKeepAliveStrategy () {@ Override public long getKeepAliveDuration (HttpResponse response, HttpContext context) {Args.notNull (response, "HTTP response"); final HeaderElementIterator it = new BasicHeaderElementIterator (response.headerIterator (HTTP.CONN_KEEP_ALIVE)); while (it.hasNext ()) {final HeaderElement he = it.nextElement (); final String param = he.getName (); final String value = he.getValue () If (value! = null & & param.equalsIgnoreCase ("timeout")) {try {return Long.parseLong (value) * 1000;} catch (final NumberFormatException ignore) {} return 1;}} HttpClients.custom () .setConnectionManager (poolingHttpClientConnectionManager) .setConnectionManagerShared (true) .setKeepAliveStrategy (myStrategy) .build () on how to solve the NoHttpResponse failed to respond problem is shared here. I hope the above content can be of some help and learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report