Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shutdown Vertx as part shutdown hook #967

Merged
merged 3 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## Next version

### Bugs fixed
- Ensure that Web3Signer stops the http server when a sigterm is received

## 24.1.1

This is an optional release for mainnet Ethereum and it includes the updated network configuration for the Sepolia, Holesky and Chiado Deneb forks.
Expand Down
15 changes: 14 additions & 1 deletion core/src/main/java/tech/pegasys/web3signer/core/Runner.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import java.util.Properties;
import java.util.StringJoiner;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;

Expand Down Expand Up @@ -174,17 +175,29 @@ public void run() {

persistPortInformation(
httpServer.actualPort(), metricsService.flatMap(MetricsService::getPort));

closeables.add(() -> shutdownVertx(vertx));
} catch (final Throwable e) {
if (artifactSignerProvider != null) {
artifactSignerProvider.close();
}
vertx.close();
shutdownVertx(vertx);
metricsService.ifPresent(MetricsService::stop);
LOG.error("Failed to initialise application", e);
throw new InitializationException(e);
}
}

private void shutdownVertx(final Vertx vertx) {
final CountDownLatch vertxShutdownLatch = new CountDownLatch(1);
vertx.close((res) -> vertxShutdownLatch.countDown());
try {
vertxShutdownLatch.await();
} catch (InterruptedException e) {
throw new IllegalStateException("Interrupted while waiting for Vertx to stop", e);
}
}

private MetricsConfiguration createMetricsConfiguration() {
if (baseConfig.getMetricsPushOptions().isPresent()) {
MetricsPushOptions options = baseConfig.getMetricsPushOptions().get();
Expand Down
Loading