You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by he...@apache.org on 2022/06/29 00:23:11 UTC

[brooklyn-server] branch master updated: synchronize creation of adjunct proxies

This is an automated email from the ASF dual-hosted git repository.

heneveld pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brooklyn-server.git


The following commit(s) were added to refs/heads/master by this push:
     new 744e0a7b1b synchronize creation of adjunct proxies
744e0a7b1b is described below

commit 744e0a7b1b28d0ff4d4ad47632775db5e3b00def
Author: Alex Heneveld <al...@cloudsoft.io>
AuthorDate: Wed Jun 29 01:14:01 2022 +0100

    synchronize creation of adjunct proxies
    
    otherwise the map can go into a weird state where it doesn't find delegates
---
 .../apache/brooklyn/core/mgmt/rebind/RebindIteration.java | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/RebindIteration.java b/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/RebindIteration.java
index fbc813f8db..9e5aa1c4a9 100644
--- a/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/RebindIteration.java
+++ b/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/RebindIteration.java
@@ -19,6 +19,8 @@
 package org.apache.brooklyn.core.mgmt.rebind;
 
 import static com.google.common.base.Preconditions.checkNotNull;
+
+import java.util.*;
 import java.util.function.Supplier;
 import static org.apache.brooklyn.core.BrooklynFeatureEnablement.FEATURE_AUTO_FIX_CATALOG_REF_ON_REBIND;
 import static org.apache.brooklyn.core.BrooklynFeatureEnablement.FEATURE_BACKWARDS_COMPATIBILITY_INFER_CATALOG_ITEM_ON_REBIND;
@@ -26,13 +28,6 @@ import static org.apache.brooklyn.core.catalog.internal.CatalogUtils.newClassLoa
 
 import java.io.IOException;
 import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
 import java.util.concurrent.Semaphore;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicInteger;
@@ -483,9 +478,10 @@ public abstract class RebindIteration {
         }
     }
 
-    protected Map<String,EntityAdjunct> adjunctProxies = MutableMap.of();
+    // creation of adjuncts can be called from different threads; it should be rare however, so easiest to synchronize
+    protected Map<String,EntityAdjunct> adjunctProxies = Collections.synchronizedMap(MutableMap.of());
     protected <T extends EntityAdjunct> T createAdjunctProxy(Class<T> adjunctType, String id) {
-        return (T) adjunctProxies.computeIfAbsent(id, (id2) -> EntityAdjuncts.createProxyForId(adjunctType, id) );
+        return (T) adjunctProxies.computeIfAbsent(id, (id2) -> EntityAdjuncts.createProxyForId(adjunctType, id));
     }
 
     protected void instantiateMementos() throws IOException {
@@ -560,6 +556,7 @@ public abstract class RebindIteration {
         }
 
         if (!adjunctProxies.isEmpty()) {
+            LOG.warn("Adjunct proxies not empty, likely indicating dangling references: "+adjunctProxies);
             adjunctProxies.entrySet().forEach(entry -> {
                 if (entry.getValue() instanceof Policy) exceptionHandler.onDanglingPolicyRef(entry.getKey());
                 else if (entry.getValue() instanceof Enricher) exceptionHandler.onDanglingEnricherRef(entry.getKey());