Skip to content
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

[ISSUE #3651] Try to fix nacos server CLOSE_WAIT #3703

Merged
merged 1 commit into from
Aug 27, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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