Skip to content

Commit

Permalink
Remove DevSerices shutdown hooks
Browse files Browse the repository at this point in the history
They are not nessesary, as the classloader close is triggered by a
shutdown hook.

Fixes quarkusio#19509
  • Loading branch information
stuartwdouglas committed Aug 20, 2021
1 parent 0fe4312 commit b6b1de0
Show file tree
Hide file tree
Showing 9 changed files with 6 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,6 @@ public void run() {
};
QuarkusClassLoader cl = (QuarkusClassLoader) Thread.currentThread().getContextClassLoader();
((QuarkusClassLoader) cl.parent()).addCloseTask(closeTask);
Thread closeHookThread = new Thread(closeTask, "Apicurio Registry container shutdown thread");
Runtime.getRuntime().addShutdownHook(closeHookThread);
((QuarkusClassLoader) cl.parent()).addCloseTask(new Runnable() {
@Override
public void run() {
Runtime.getRuntime().removeShutdownHook(closeHookThread);
}
});
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,6 @@ public void run() {
};
QuarkusClassLoader cl = (QuarkusClassLoader) Thread.currentThread().getContextClassLoader();
((QuarkusClassLoader) cl.parent()).addCloseTask(closeTask);
Thread closeHookThread = new Thread(closeTask, "Database shutdown thread");
Runtime.getRuntime().addShutdownHook(closeHookThread);
((QuarkusClassLoader) cl.parent()).addCloseTask(new Runnable() {
@Override
public void run() {
Runtime.getRuntime().removeShutdownHook(closeHookThread);
}
});
}
databases = closeableList;
cachedProperties = propertiesMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,6 @@ public DevServicesKafkaBrokerBuildItem startKafkaDevService(
};
QuarkusClassLoader cl = (QuarkusClassLoader) Thread.currentThread().getContextClassLoader();
((QuarkusClassLoader) cl.parent()).addCloseTask(closeTask);
Thread closeHookThread = new Thread(closeTask, "Kafka container shutdown thread");
Runtime.getRuntime().addShutdownHook(closeHookThread);
((QuarkusClassLoader) cl.parent()).addCloseTask(() -> Runtime.getRuntime().removeShutdownHook(closeHookThread));
}
cfg = configuration;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,6 @@ public void run() {
};
QuarkusClassLoader cl = (QuarkusClassLoader) Thread.currentThread().getContextClassLoader();
((QuarkusClassLoader) cl.parent()).addCloseTask(closeTask);
Thread closeHookThread = new Thread(closeTask, "Mongo container shutdown thread");
Runtime.getRuntime().addShutdownHook(closeHookThread);
((QuarkusClassLoader) cl.parent()).addCloseTask(new Runnable() {
@Override
public void run() {
Runtime.getRuntime().removeShutdownHook(closeHookThread);
}
});
}
closeables = currentCloseables;
capturedProperties = currentCapturedProperties;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,6 @@ public void run() {
};
QuarkusClassLoader cl = (QuarkusClassLoader) Thread.currentThread().getContextClassLoader();
((QuarkusClassLoader) cl.parent()).addCloseTask(closeTask);
Thread closeHookThread = new Thread(closeTask, "Keycloak container shutdown thread");
Runtime.getRuntime().addShutdownHook(closeHookThread);
((QuarkusClassLoader) cl.parent()).addCloseTask(new Runnable() {
@Override
public void run() {
Runtime.getRuntime().removeShutdownHook(closeHookThread);
}
});
}

capturedKeycloakUrl = startResult.url + "/auth";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,6 @@ public void startRedisContainers(LaunchModeBuildItem launchMode,
};
QuarkusClassLoader cl = (QuarkusClassLoader) Thread.currentThread().getContextClassLoader();
((QuarkusClassLoader) cl.parent()).addCloseTask(closeTask);
Thread closeHookThread = new Thread(closeTask, "Redis container shutdown thread");
Runtime.getRuntime().addShutdownHook(closeHookThread);
((QuarkusClassLoader) cl.parent()).addCloseTask(() -> Runtime.getRuntime().removeShutdownHook(closeHookThread));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,6 @@ public DevServicesAmqpBrokerBuildItem startAmqpDevService(
};
QuarkusClassLoader cl = (QuarkusClassLoader) Thread.currentThread().getContextClassLoader();
((QuarkusClassLoader) cl.parent()).addCloseTask(closeTask);
Thread closeHookThread = new Thread(closeTask, "AMQP container shutdown thread");
Runtime.getRuntime().addShutdownHook(closeHookThread);
((QuarkusClassLoader) cl.parent()).addCloseTask(() -> Runtime.getRuntime().removeShutdownHook(closeHookThread));
}
cfg = configuration;
return artemis;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,6 @@ public void run() {
};
QuarkusClassLoader cl = (QuarkusClassLoader) Thread.currentThread().getContextClassLoader();
((QuarkusClassLoader) cl.parent()).addCloseTask(closeTask);
Thread closeHookThread = new Thread(closeTask, "Vault container shutdown thread");
Runtime.getRuntime().addShutdownHook(closeHookThread);
((QuarkusClassLoader) cl.parent()).addCloseTask(new Runnable() {
@Override
public void run() {
Runtime.getRuntime().removeShutdownHook(closeHookThread);
}
});
}
for (Map.Entry<String, String> entry : connectionProperties.entrySet()) {
devConfig.produce(new DevServicesConfigResultBuildItem(entry.getKey(), entry.getValue()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ public Thread newThread(Runnable r) {
.setTest(true)
.build()
.bootstrap();
shutdownTasks.add(curatedApplication::close);
}

if (curatedApplication.getAppModel().getUserDependencies().isEmpty()) {
Expand Down Expand Up @@ -1260,7 +1261,11 @@ public void close() {
ConfigProviderResolver.setInstance(null);
}
}
Runtime.getRuntime().removeShutdownHook(shutdownHook);
try {
Runtime.getRuntime().removeShutdownHook(shutdownHook);
} catch (Throwable t) {
//won't work if we are already shutting down
}
}
}
}
Expand Down

0 comments on commit b6b1de0

Please sign in to comment.