mirror of
https://github.com/alibaba/canal.git
synced 2026-11-04 00:30:15 +08:00
fix: close HttpClient after binlog download to prevent resource leak (#5579)
BinlogDownloadQueue.download() creates a CloseableHttpClient for each download but never closes it. Over time this exhausts connection pool resources. Wrap the HTTP execution in a try-finally block to ensure the client is always closed. Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -189,6 +189,7 @@ public class BinlogDownloadQueue {
|
|||||||
httpClient = HttpClientBuilder.create().setMaxConnPerRoute(50).setMaxConnTotal(100).build();
|
httpClient = HttpClientBuilder.create().setMaxConnPerRoute(50).setMaxConnTotal(100).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
HttpGet httpGet = new HttpGet(downloadLink);
|
HttpGet httpGet = new HttpGet(downloadLink);
|
||||||
RequestConfig requestConfig = RequestConfig.custom()
|
RequestConfig requestConfig = RequestConfig.custom()
|
||||||
.setConnectTimeout(TIMEOUT)
|
.setConnectTimeout(TIMEOUT)
|
||||||
@@ -202,6 +203,9 @@ public class BinlogDownloadQueue {
|
|||||||
throw new RuntimeException("download failed , url:" + downloadLink + " , statusCode:" + statusCode);
|
throw new RuntimeException("download failed , url:" + downloadLink + " , statusCode:" + statusCode);
|
||||||
}
|
}
|
||||||
saveFile(new File(destDir), "mysql-bin." + fileName, response);
|
saveFile(new File(destDir), "mysql-bin." + fileName, response);
|
||||||
|
} finally {
|
||||||
|
httpClient.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void saveFile(File parentFile, String fileName, HttpResponse response) throws IOException {
|
private static void saveFile(File parentFile, String fileName, HttpResponse response) throws IOException {
|
||||||
|
|||||||
Reference in New Issue
Block a user