Skip to content

Commit

Permalink
Merge pull request quarkusio#19522 from stuartwdouglas/19509
Browse files Browse the repository at this point in the history
Remove DevServices shutdown hooks
  • Loading branch information
gsmet authored Aug 20, 2021
2 parents adcb9df + b6b1de0 commit ef4bcaf
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 @@ -339,6 +339,7 @@ public Thread newThread(Runnable r) {
.setTest(true)
.build()
.bootstrap();
shutdownTasks.add(curatedApplication::close);
}

if (curatedApplication.getAppModel().getUserDependencies().isEmpty()) {
Expand Down Expand Up @@ -1269,7 +1270,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 ef4bcaf

Please sign in to comment.