aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>2017-03-06 13:46:46 +0100
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>2017-03-13 16:00:01 +0100
commit806fba0dce48b84d52227a800cf5e5d46424b10e (patch)
tree2b8ca90c39dd93117d1390ea6f5c4791ff9fdc6d
parent9730736b59ed79bd14149804189b8843b43737ac (diff)
downloadsonarqube-806fba0dce48b84d52227a800cf5e5d46424b10e.tar.gz
sonarqube-806fba0dce48b84d52227a800cf5e5d46424b10e.zip
SONAR-7500 fix thread leaks when Web fails during startup
-rw-r--r--sonar-core/src/main/java/org/sonar/core/platform/ComponentContainer.java25
1 files changed, 12 insertions, 13 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/platform/ComponentContainer.java b/sonar-core/src/main/java/org/sonar/core/platform/ComponentContainer.java
index 5005de890e1..f383b8f40fa 100644
--- a/sonar-core/src/main/java/org/sonar/core/platform/ComponentContainer.java
+++ b/sonar-core/src/main/java/org/sonar/core/platform/ComponentContainer.java
@@ -20,6 +20,7 @@
package org.sonar.core.platform;
import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.Iterator;
@@ -170,8 +171,11 @@ public class ComponentContainer implements ContainerPopulator.Container {
}
public ComponentContainer stopComponents(boolean swallowException) {
+ stopChildren();
try {
- pico.stop();
+ if (pico.getLifecycleState().isStarted()) {
+ pico.stop();
+ }
pico.dispose();
} catch (RuntimeException e) {
@@ -179,7 +183,6 @@ public class ComponentContainer implements ContainerPopulator.Container {
throw PicoUtils.propagate(e);
}
} finally {
- removeChildren();
if (parent != null) {
parent.removeChild(this);
}
@@ -187,6 +190,13 @@ public class ComponentContainer implements ContainerPopulator.Container {
return this;
}
+ private void stopChildren() {
+ // loop over a copy of list of children in reverse order, both to stop last added child first and because children
+ // remove themselves from the list of children of their parent (ie. changing this.children)
+ Lists.reverse(new ArrayList<>(this.children))
+ .forEach(ComponentContainer::stopComponents);
+ }
+
/**
* @since 3.5
*/
@@ -297,17 +307,6 @@ public class ComponentContainer implements ContainerPopulator.Container {
return this;
}
- private ComponentContainer removeChildren() {
- Iterator<ComponentContainer> childrenIterator = children.iterator();
- while (childrenIterator.hasNext()) {
- ComponentContainer child = childrenIterator.next();
- if (pico.removeChildContainer(child.pico)) {
- childrenIterator.remove();
- }
- }
- return this;
- }
-
public ComponentContainer createChild() {
return new ComponentContainer(this);
}