Github user geomacy commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/453#discussion_r89106124
  
    --- Diff: 
core/src/main/java/org/apache/brooklyn/core/mgmt/internal/LocalEntityManager.java
 ---
    @@ -212,13 +213,41 @@ public EntityTypeRegistry getEntityTypeRegistry() {
     
         @Override
         public Iterable<Entity> getAllEntitiesInApplication(Application 
application) {
    +        // To fix https://issues.apache.org/jira/browse/BROOKLYN-352, we 
need to synchronize on
    +        // preRegisteredEntitiesById and preManagedEntitiesById while 
iterating over them (because
    +        // they are synchronizedMaps). entityProxiesById is a 
ConcurrentMap, so no need to 
    +        // synchronize on that.
    +        // Only synchronize on one at a time, to avoid the risk of 
deadlock.
    +        
             Predicate<Entity> predicate = 
EntityPredicates.applicationIdEqualTo(application.getId());
    -        Iterable<Entity> allentities = 
Iterables.concat(preRegisteredEntitiesById.values(), 
preManagedEntitiesById.values(), entityProxiesById.values());
    -        Iterable<Entity> result = Iterables.filter(allentities, predicate);
    -        return ImmutableSet.copyOf(Iterables.transform(result, new 
Function<Entity, Entity>() {
    -            @Override public Entity apply(Entity input) {
    -                return Entities.proxy(input);
    -            }}));
    +        Set<Entity> result = Sets.newLinkedHashSet();
    +        
    +        synchronized (preRegisteredEntitiesById) {
    --- End diff --
    
    Maybe it would be worth making `preRegisteredEntitiesById` and 
`preManagedEntitiesById` private, and providing access to them with code like 
this loop, but put into a `protected` method.  At the moment it's not 
impossible that some derived class in future would again use one of the maps 
but forget the synchronization. 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to