[java-identity-provider] branch maint-4 updated: IDP-2265 - Metrics reporter fails to close HTTP response

Scott Cantor cantor.2 at osu.edu
Thu Mar 14 19:13:42 UTC 2024


This is an automated email from the git hooks/post-receive script.

scantor pushed a commit to branch maint-4
in repository java-identity-provider.

View the commit online:
http://git.shibboleth.net/view/?p=java-identity-provider.git;a=commit;h=7a76008f87bb55d09251eea2594b758c814e4fed

The following commit(s) were added to refs/heads/maint-4 by this push:
     new 7a76008f8 IDP-2265 - Metrics reporter fails to close HTTP response
7a76008f8 is described below

commit 7a76008f87bb55d09251eea2594b758c814e4fed
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Thu Mar 14 15:13:19 2024 -0400

    IDP-2265 - Metrics reporter fails to close HTTP response
    
    https://shibboleth.atlassian.net/browse/IDP-2265
    
    Backport from fix applied in OpenSAML 5.
---
 .../shibboleth/idp/metrics/impl/HTTPReporter.java  | 26 ++++++++++++++--------
 1 file changed, 17 insertions(+), 9 deletions(-)

diff --git a/idp-core/src/main/java/net/shibboleth/idp/metrics/impl/HTTPReporter.java b/idp-core/src/main/java/net/shibboleth/idp/metrics/impl/HTTPReporter.java
index d416a5f62..f7ab2c5d8 100644
--- a/idp-core/src/main/java/net/shibboleth/idp/metrics/impl/HTTPReporter.java
+++ b/idp-core/src/main/java/net/shibboleth/idp/metrics/impl/HTTPReporter.java
@@ -32,6 +32,7 @@ import org.apache.http.HttpResponse;
 import org.apache.http.HttpStatus;
 import org.apache.http.client.HttpClient;
 import org.apache.http.client.entity.EntityBuilder;
+import org.apache.http.client.methods.CloseableHttpResponse;
 import org.apache.http.client.methods.HttpPost;
 import org.apache.http.client.methods.HttpUriRequest;
 import org.apache.http.client.protocol.HttpClientContext;
@@ -260,13 +261,20 @@ public class HTTPReporter extends ScheduledReporter implements InitializableComp
                 entityBuilder.setBinary(output.toByteArray());
                 httpRequest.setEntity(entityBuilder.build());
 
-                final HttpResponse response = httpClient.execute(httpRequest, httpContext);
-                HttpClientSecuritySupport.checkTLSCredentialEvaluated(httpContext, httpRequest.getURI().getScheme());
+                HttpResponse response = null;
+                try {
+                    response = httpClient.execute(httpRequest, httpContext);
+                    HttpClientSecuritySupport.checkTLSCredentialEvaluated(httpContext, httpRequest.getURI().getScheme());
                 
-                if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
-                    log.debug("Metrics delivered successfully to collector");
-                } else {
-                    log.error("Collector responded with HTTP status {}", response.getStatusLine().getStatusCode());
+                    if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
+                        log.debug("Metrics delivered successfully to collector");
+                    } else {
+                        log.error("Collector responded with HTTP status {}", response.getStatusLine().getStatusCode());
+                    }
+                } finally {
+                    if (response instanceof CloseableHttpResponse) {
+                        ((CloseableHttpResponse) response).close();
+                    }
                 }
             } catch (final IOException e) {
                 log.error("Error sending metric registry to collection point {}", collectorURL, e);
@@ -276,9 +284,9 @@ public class HTTPReporter extends ScheduledReporter implements InitializableComp
     
     /** {@inheritDoc} */
     @Override
-    public void report(final SortedMap<String, Gauge> gauges, final SortedMap<String, Counter> counters,
-            final SortedMap<String, Histogram> histograms, final SortedMap<String, Meter> meters,
-            final SortedMap<String, Timer> timers) {
+    public void report(@SuppressWarnings("rawtypes") final SortedMap<String, Gauge> gauges,
+            final SortedMap<String, Counter> counters, final SortedMap<String, Histogram> histograms,
+            final SortedMap<String, Meter> meters, final SortedMap<String, Timer> timers) {
         throw new UnsupportedOperationException("The per-metric report method should never be called.");
     }
 

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list