Skip to content

Commit

Permalink
[MSC-93] Avoid sending an immediateDependencyAvailable notification w…
Browse files Browse the repository at this point in the history
…ithout an immediateDependencyUnavailable counterpart.

Such a scenario could happen during a service installation, if the ServiceRegistrationImpl object gets an addDependent call
before the instance installation is committed, but after the instance was set.
This behavior could also lead to a missing immediateDependencyUnavailable call if a dependent is added to a service whose
ongoing installation will be rolled back.
  • Loading branch information
fl4via committed May 18, 2011
1 parent 3046db6 commit 714f740
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Expand Up @@ -279,6 +279,15 @@ void rollbackInstallation() {
(new RemoveTask()).run();
}

/**
* Return {@code true} only if this service controller installation is committed.
*/
boolean isInstallationCommitted() {
assert holdsLock(this);
// should not be NEW nor CANCELLED
return state.compareTo(Substate.CANCELLED) > 0;
}

/**
* Identify the transition to take. Call under lock.
*
Expand Down
Expand Up @@ -99,10 +99,17 @@ public void addDependent(final Dependent dependent) {
return;
}
synchronized (instance) {
instance.newDependent(name, dependent, tasks);
synchronized (dependents) {
dependents.add(dependent);
}
// if instance is not fully installed yet, we need to be on a synchronized(instance) block to avoid
// creation and execution of ServiceAvailableTask before immediateDependencyUnavailable is invoked on
// new dependent
if (!instance.isInstallationCommitted()) {
dependent.immediateDependencyUnavailable(name);
return;
}
instance.newDependent(name, dependent, tasks);
instance.addAsyncTasks(tasks.size() + 1);
}
}
Expand Down

0 comments on commit 714f740

Please sign in to comment.