Skip to content

Commit

Permalink
Try to fix nacos server CLOSE_WAIT (#3703)
Browse files Browse the repository at this point in the history
  • Loading branch information
KomachiSion authored Aug 27, 2020
1 parent e65c0f3 commit 2d790a0
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions naming/src/main/java/com/alibaba/nacos/naming/misc/HttpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -465,10 +465,9 @@ public static void asyncHttpGetLarge(String url, Map<String, String> headers, by
* @return {@link HttpResult} as response
*/
public static HttpResult httpPutLarge(String url, Map<String, String> headers, byte[] content) {
try {
HttpClientBuilder builder = HttpClients.custom().setUserAgent(UtilsAndCommons.SERVER_VERSION)
.setConnectionTimeToLive(500, TimeUnit.MILLISECONDS);
CloseableHttpClient httpClient = builder.build();
HttpClientBuilder builder = HttpClients.custom().setUserAgent(UtilsAndCommons.SERVER_VERSION)
.setConnectionTimeToLive(500, TimeUnit.MILLISECONDS);
try (CloseableHttpClient httpClient = builder.build();) {

HttpPut httpPut = new HttpPut(url);
for (Map.Entry<String, String> entry : headers.entrySet()) {
Expand Down Expand Up @@ -498,11 +497,10 @@ public static HttpResult httpPutLarge(String url, Map<String, String> headers, b
* @return {@link HttpResult} as response
*/
public static HttpResult httpGetLarge(String url, Map<String, String> headers, String content) {

try {
HttpClientBuilder builder = HttpClients.custom();
builder.setUserAgent(UtilsAndCommons.SERVER_VERSION);
builder.setConnectionTimeToLive(500, TimeUnit.MILLISECONDS);
HttpClientBuilder builder = HttpClients.custom();
builder.setUserAgent(UtilsAndCommons.SERVER_VERSION);
builder.setConnectionTimeToLive(500, TimeUnit.MILLISECONDS);
try (CloseableHttpClient httpClient = builder.build();) {

HttpGetWithEntity httpGetWithEntity = new HttpGetWithEntity();
httpGetWithEntity.setURI(new URI(url));
Expand All @@ -512,7 +510,7 @@ public static HttpResult httpGetLarge(String url, Map<String, String> headers, S
}

httpGetWithEntity.setEntity(new StringEntity(content, ContentType.create("application/json", "UTF-8")));
CloseableHttpClient httpClient = builder.build();

HttpResponse response = httpClient.execute(httpGetWithEntity);
HttpEntity entity = response.getEntity();

Expand All @@ -535,12 +533,11 @@ public static HttpResult httpGetLarge(String url, Map<String, String> headers, S
* @return {@link HttpResult} as response
*/
public static HttpResult httpPostLarge(String url, Map<String, String> headers, String content) {
try {
HttpClientBuilder builder = HttpClients.custom();
builder.setUserAgent(UtilsAndCommons.SERVER_VERSION);
builder.setConnectionTimeToLive(500, TimeUnit.MILLISECONDS);
HttpClientBuilder builder = HttpClients.custom();
builder.setUserAgent(UtilsAndCommons.SERVER_VERSION);
builder.setConnectionTimeToLive(500, TimeUnit.MILLISECONDS);
try (CloseableHttpClient httpClient = builder.build();) {

CloseableHttpClient httpClient = builder.build();
HttpPost httpost = new HttpPost(url);

for (Map.Entry<String, String> entry : headers.entrySet()) {
Expand Down

0 comments on commit 2d790a0

Please sign in to comment.