From 402175e7b4e46692703e8ed3762ec71a29262492 Mon Sep 17 00:00:00 2001 From: "James R. Perkins" Date: Tue, 6 Aug 2024 09:27:13 -0700 Subject: [PATCH] [65] Do not attempt to shut down more than once. Signed-off-by: James R. Perkins --- .../tools/server/AbstractServerManager.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/wildfly/plugin/tools/server/AbstractServerManager.java b/src/main/java/org/wildfly/plugin/tools/server/AbstractServerManager.java index 8abafd2..86638c8 100644 --- a/src/main/java/org/wildfly/plugin/tools/server/AbstractServerManager.java +++ b/src/main/java/org/wildfly/plugin/tools/server/AbstractServerManager.java @@ -36,6 +36,7 @@ abstract class AbstractServerManager implements private final boolean shutdownOnClose; private final DeploymentManager deploymentManager; private final AtomicBoolean closed; + private final AtomicBoolean shutdown; protected AbstractServerManager(final ProcessHandle process, final T client, final boolean shutdownOnClose) { @@ -44,6 +45,7 @@ protected AbstractServerManager(final ProcessHandle process, final T client, this.shutdownOnClose = shutdownOnClose; deploymentManager = DeploymentManager.create(client); this.closed = new AtomicBoolean(false); + this.shutdown = new AtomicBoolean(false); } @Override @@ -154,7 +156,9 @@ public void executeReload(final ModelNode reloadOp) throws IOException, Operatio @Override public void shutdown(final long timeout) throws IOException { checkState(); - internalShutdown(client(), timeout); + if (shutdown.compareAndSet(false, true)) { + internalShutdown(client(), timeout); + } waitForShutdown(client()); } @@ -165,7 +169,9 @@ public CompletableFuture shutdownAsync(final long timeout) { if (process != null) { return CompletableFuture.supplyAsync(() -> { try { - internalShutdown(client, timeout); + if (shutdown.compareAndSet(false, true)) { + internalShutdown(client, timeout); + } } catch (IOException e) { throw new CompletionException("Failed to shutdown server.", e); } @@ -189,7 +195,9 @@ public CompletableFuture shutdownAsync(final long timeout) { } return CompletableFuture.supplyAsync(() -> { try { - internalShutdown(client, timeout); + if (shutdown.compareAndSet(false, true)) { + internalShutdown(client, timeout); + } } catch (IOException e) { throw new CompletionException("Failed to shutdown server.", e); } @@ -223,7 +231,9 @@ void internalClose(final boolean shutdownOnClose, final boolean waitForShutdown) if (closed.compareAndSet(false, true)) { if (shutdownOnClose) { try { - internalShutdown(client, 0); + if (shutdown.compareAndSet(false, true)) { + internalShutdown(client, 0); + } if (waitForShutdown) { waitForShutdown(client); }