summaryrefslogtreecommitdiffstats
path: root/container-disc
diff options
context:
space:
mode:
authorBjørn Christian Seime <bjorncs@verizonmedia.com>2022-01-24 18:06:05 +0100
committerBjørn Christian Seime <bjorncs@verizonmedia.com>2022-01-25 09:43:56 +0100
commit33de9a9a6c65764791cb07aab7d51fe09ee28725 (patch)
tree4b0a8afd858aaecf950a5c8c392c5dcf99cbdd63 /container-disc
parent1cb62247d4b68a5f528cfbba36d8ae8bf954cb8e (diff)
Respect topological ordering when releasing shared resources
Diffstat (limited to 'container-disc')
-rw-r--r--container-disc/src/main/java/com/yahoo/container/jdisc/component/Deconstructor.java13
-rw-r--r--container-disc/src/test/java/com/yahoo/container/jdisc/component/DeconstructorTest.java3
2 files changed, 12 insertions, 4 deletions
diff --git a/container-disc/src/main/java/com/yahoo/container/jdisc/component/Deconstructor.java b/container-disc/src/main/java/com/yahoo/container/jdisc/component/Deconstructor.java
index acf4a494a96..747c2865ea1 100644
--- a/container-disc/src/main/java/com/yahoo/container/jdisc/component/Deconstructor.java
+++ b/container-disc/src/main/java/com/yahoo/container/jdisc/component/Deconstructor.java
@@ -76,9 +76,8 @@ public class Deconstructor implements ComponentDeconstructor {
} else if (component instanceof Provider) {
destructibleComponents.add((Deconstructable) component);
} else if (component instanceof SharedResource) {
- log.log(FINE, () -> "Releasing container reference to resource " + component);
- // No need to delay release, as jdisc does ref-counting
- ((SharedResource) component).release();
+ // Release shared resources in same order as other components in case of usage without reference counting
+ destructibleComponents.add(new SharedResourceReleaser(component));
}
}
if (!destructibleComponents.isEmpty() || !bundles.isEmpty()) {
@@ -104,6 +103,14 @@ public class Deconstructor implements ComponentDeconstructor {
}
}
+ private static class SharedResourceReleaser implements Deconstructable {
+ final SharedResource resource;
+
+ private SharedResourceReleaser(Object resource) { this.resource = (SharedResource) resource; }
+
+ @Override public void deconstruct() { resource.release(); }
+ }
+
private static class DestructComponentTask implements Runnable {
private final Random random = new Random(System.nanoTime());
diff --git a/container-disc/src/test/java/com/yahoo/container/jdisc/component/DeconstructorTest.java b/container-disc/src/test/java/com/yahoo/container/jdisc/component/DeconstructorTest.java
index e9a9d310380..0a7d3f45e82 100644
--- a/container-disc/src/test/java/com/yahoo/container/jdisc/component/DeconstructorTest.java
+++ b/container-disc/src/test/java/com/yahoo/container/jdisc/component/DeconstructorTest.java
@@ -57,9 +57,10 @@ public class DeconstructorTest {
}
@Test
- public void require_shared_resource_released() {
+ public void require_shared_resource_released() throws InterruptedException {
TestSharedResource sharedResource = new TestSharedResource();
deconstructor.deconstruct(List.of(sharedResource), emptyList());
+ waitForDeconstructToComplete(() -> sharedResource.released);
assertTrue(sharedResource.released);
}