From 4ffa9efa277156c60b8a140472422b588318451d Mon Sep 17 00:00:00 2001 From: Jason Frame Date: Fri, 2 Feb 2024 16:28:32 +1000 Subject: [PATCH 1/3] Shutdown Vertx when Web3Signer receives a sigterm --- .../java/tech/pegasys/web3signer/core/Runner.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/core/src/main/java/tech/pegasys/web3signer/core/Runner.java b/core/src/main/java/tech/pegasys/web3signer/core/Runner.java index 13dbc8a88..ebc317a4d 100644 --- a/core/src/main/java/tech/pegasys/web3signer/core/Runner.java +++ b/core/src/main/java/tech/pegasys/web3signer/core/Runner.java @@ -42,8 +42,10 @@ 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; +import java.util.concurrent.TimeoutException; import io.netty.handler.codec.http.HttpHeaderValues; import io.vertx.core.Handler; @@ -174,6 +176,8 @@ public void run() { persistPortInformation( httpServer.actualPort(), metricsService.flatMap(MetricsService::getPort)); + + closeables.add(() -> shutdownVertx(vertx)); } catch (final Throwable e) { if (artifactSignerProvider != null) { artifactSignerProvider.close(); @@ -185,6 +189,16 @@ public void run() { } } + 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(); From b41aac9468499d5a813c0bb2f910228f61f6022f Mon Sep 17 00:00:00 2001 From: Jason Frame Date: Fri, 2 Feb 2024 16:32:03 +1000 Subject: [PATCH 2/3] Use new Vertx shutdown method when startup fails --- core/src/main/java/tech/pegasys/web3signer/core/Runner.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/core/src/main/java/tech/pegasys/web3signer/core/Runner.java b/core/src/main/java/tech/pegasys/web3signer/core/Runner.java index ebc317a4d..7161a1d5b 100644 --- a/core/src/main/java/tech/pegasys/web3signer/core/Runner.java +++ b/core/src/main/java/tech/pegasys/web3signer/core/Runner.java @@ -45,7 +45,6 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; import io.netty.handler.codec.http.HttpHeaderValues; import io.vertx.core.Handler; @@ -182,7 +181,7 @@ public void run() { if (artifactSignerProvider != null) { artifactSignerProvider.close(); } - vertx.close(); + shutdownVertx(vertx); metricsService.ifPresent(MetricsService::stop); LOG.error("Failed to initialise application", e); throw new InitializationException(e); From 912b1f2c40d438a3f64b058359e0c5a7bf262259 Mon Sep 17 00:00:00 2001 From: Jason Frame Date: Fri, 2 Feb 2024 16:34:57 +1000 Subject: [PATCH 3/3] add changelog --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d1a7b67f7..06d2456f4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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.