@@ -428,8 +428,9 @@ public ClassicHttpResponse executeRequest(Endpoint server, Map<String, Object> r
428
428
429
429
HttpClientContext context = HttpClientContext .create ();
430
430
431
+ ClassicHttpResponse httpResponse = null ;
431
432
try {
432
- ClassicHttpResponse httpResponse = httpClient .executeOpen (null , req , context );
433
+ httpResponse = httpClient .executeOpen (null , req , context );
433
434
boolean serverCompression = ClientConfigProperties .COMPRESS_SERVER_RESPONSE .getOrDefault (requestConfig );
434
435
httpResponse .setEntity (wrapResponseEntity (httpResponse .getEntity (), httpResponse .getCode (), serverCompression , useHttpCompression , lz4Factory , requestConfig ));
435
436
@@ -448,14 +449,26 @@ public ClassicHttpResponse executeRequest(Endpoint server, Map<String, Object> r
448
449
return httpResponse ;
449
450
450
451
} catch (UnknownHostException e ) {
452
+ closeQuietly (httpResponse );
451
453
LOG .warn ("Host '{}' unknown" , server .getBaseURL ());
452
454
throw e ;
453
455
} catch (ConnectException | NoRouteToHostException e ) {
456
+ closeQuietly (httpResponse );
454
457
LOG .warn ("Failed to connect to '{}': {}" , server .getBaseURL (), e .getMessage ());
455
458
throw e ;
456
459
}
457
460
}
458
461
462
+ public void closeQuietly (ClassicHttpResponse httpResponse ) {
463
+ if (httpResponse != null ) {
464
+ try {
465
+ httpResponse .close ();
466
+ } catch (IOException e ) {
467
+ LOG .warn ("Failed to close response" );
468
+ }
469
+ }
470
+ }
471
+
459
472
private static final ContentType CONTENT_TYPE = ContentType .create (ContentType .TEXT_PLAIN .getMimeType (), "UTF-8" );
460
473
461
474
private void addHeaders (HttpPost req , Map <String , Object > requestConfig ) {
0 commit comments