[java-shib-profile] branch main updated: JSPROF-4 - Use metric removal to limit heap usage in loop detection

Scott Cantor cantor.2 at osu.edu
Wed Dec 6 14:09:21 UTC 2023


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

scantor pushed a commit to branch main
in repository java-shib-profile.

View the commit online:
http://git.shibboleth.net/view/?p=java-shib-profile.git;a=commit;h=fa2ab19d6f2cb162a8ecc2c2b08e7dd0671d6268

The following commit(s) were added to refs/heads/main by this push:
     new fa2ab19  JSPROF-4 - Use metric removal to limit heap usage in loop detection
fa2ab19 is described below

commit fa2ab19d6f2cb162a8ecc2c2b08e7dd0671d6268
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Wed Dec 6 09:09:18 2023 -0500

    JSPROF-4 - Use metric removal to limit heap usage in loop detection
    
    https://shibboleth.atlassian.net/browse/JSPROF-4
    
    Add a backstop for registry raising various exceptions.
---
 .../context/logic/LoopDetectionPredicate.java      | 35 ++++++++++++----------
 1 file changed, 20 insertions(+), 15 deletions(-)

diff --git a/shib-profile-api/src/main/java/net/shibboleth/profile/context/logic/LoopDetectionPredicate.java b/shib-profile-api/src/main/java/net/shibboleth/profile/context/logic/LoopDetectionPredicate.java
index 66b4ac5..b14b8c2 100644
--- a/shib-profile-api/src/main/java/net/shibboleth/profile/context/logic/LoopDetectionPredicate.java
+++ b/shib-profile-api/src/main/java/net/shibboleth/profile/context/logic/LoopDetectionPredicate.java
@@ -107,21 +107,26 @@ public class LoopDetectionPredicate extends AbstractRelyingPartyPredicate {
         if (username != null && rpCtx != null && rpCtx.getRelyingPartyId() != null) {
             String meterName = relyingPartyMap.get(rpCtx.getRelyingPartyId());
             if (meterName != null) {
-                meterName = MetricRegistry.name("net.shibboleth.idp.loopDetection", meterName,
-                        username.replace(".",""));
-                
-                final Meter meter = privateRegistry.meter(meterName,
-                        new MetricSupplier<Meter>() {
-                            public Meter newMetric() {
-                                return new Meter(new SlidingTimeWindowMovingAverages());
-                            }
-                        });
-                meter.mark();
-                final double rate = meter.getOneMinuteRate();
-                if (rate > threshold) {
-                    log.warn("Meter {} rate of {} exceeded threshold of {}", meterName, rate, threshold);
-                    privateRegistry.remove(meterName);
-                    return true;
+                try {
+                    meterName = MetricRegistry.name("net.shibboleth.idp.loopDetection", meterName,
+                            username.replace(".",""));
+                    
+                    final Meter meter = privateRegistry.meter(meterName,
+                            new MetricSupplier<Meter>() {
+                                public Meter newMetric() {
+                                    return new Meter(new SlidingTimeWindowMovingAverages());
+                                }
+                            });
+                    meter.mark();
+                    final double rate = meter.getOneMinuteRate();
+                    if (rate > threshold) {
+                        log.warn("Meter {} rate of {} exceeded threshold of {}", meterName, rate, threshold);
+                        privateRegistry.remove(meterName);
+                        return true;
+                    }
+                } catch (final IllegalArgumentException e) {
+                    // Just swallow this, it should reflect a race condition manipulating the metric for that user/SP.
+                    log.warn("Error manipulating private MetricRegistry", e);
                 }
             }
         }

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


More information about the commits mailing list