NPE when undeploying several instances of the same verticle that share the same isolationGroup - closes #3074

This commit is contained in:
Julien Viet
2019-08-19 12:16:37 +02:00
parent f13add9017
commit 14effa3691
3 changed files with 17 additions and 5 deletions

View File

@@ -418,9 +418,8 @@ public class DeploymentManager {
icl = new IsolatingClassLoader(urls.toArray(new URL[urls.size()]), getCurrentClassLoader(),
options.getIsolatedClasses());
classloaders.put(isolationGroup, icl);
} else {
icl.refCount++;
}
icl.refCount += options.getInstances();
cl = icl;
}
}

View File

@@ -31,7 +31,7 @@ public class IsolatingClassLoader extends URLClassLoader {
public IsolatingClassLoader(URL[] urls, ClassLoader parent, List<String> isolatedClasses) {
super(urls, parent);
this.isolatedClasses = isolatedClasses;
this.refCount = 1;
this.refCount = 0;
}
@Override

View File

@@ -1161,12 +1161,24 @@ public class DeploymentTest extends VertxTestBase {
@Test
public void testCloseIsolationGroup() throws Exception {
testCloseIsolationGroup(1);
}
@Test
public void testCloseIsolationGroupMultiInstances() throws Exception {
testCloseIsolationGroup(3);
}
private void testCloseIsolationGroup(int instances) throws Exception {
boolean expectedSuccess = Thread.currentThread().getContextClassLoader() instanceof URLClassLoader;
String dir = createClassOutsideClasspath("MyVerticle");
List<String> extraClasspath = Arrays.asList(dir);
List<String> extraClasspath = Collections.singletonList(dir);
Vertx vertx = Vertx.vertx();
try {
DeploymentOptions options = new DeploymentOptions().setIsolationGroup("somegroup").setExtraClasspath(extraClasspath);
DeploymentOptions options = new DeploymentOptions()
.setInstances(instances)
.setIsolationGroup("somegroup")
.setExtraClasspath(extraClasspath);
vertx.deployVerticle("java:" + ExtraCPVerticleNotInParentLoader.class.getCanonicalName(), options, onSuccess(id -> {
vertx.close(onSuccess(v -> {
assertTrue(ExtraCPVerticleNotInParentLoader.cl.isClosed());
@@ -1181,6 +1193,7 @@ public class DeploymentTest extends VertxTestBase {
ExtraCPVerticleNotInParentLoader.cl = null;
}
}
public static class ParentVerticle extends AbstractVerticle {
@Override