From f143babcf79c1558a1c8b4baf38c03f45e6d61c5 Mon Sep 17 00:00:00 2001 From: Jan Bartel Date: Mon, 24 Aug 2020 17:21:53 +0200 Subject: [PATCH] Issue #5087 Use lock to protect Deployment Mgr startup errors (#5139) * Issue #5087 Use lock to protect Deployment Mgr startup errors Signed-off-by: Jan Bartel --- .../jetty/deploy/DeploymentManager.java | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/DeploymentManager.java b/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/DeploymentManager.java index 64c8ea1fe73..1fa74262724 100644 --- a/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/DeploymentManager.java +++ b/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/DeploymentManager.java @@ -49,6 +49,8 @@ import org.eclipse.jetty.util.component.ContainerLifeCycle; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.resource.Resource; +import org.eclipse.jetty.util.thread.Locker; +import org.eclipse.jetty.util.thread.Locker.Lock; import org.eclipse.jetty.xml.XmlConfiguration; /** @@ -69,7 +71,6 @@ import org.eclipse.jetty.xml.XmlConfiguration; public class DeploymentManager extends ContainerLifeCycle { private static final Logger LOG = Log.getLogger(DeploymentManager.class); - private MultiException onStartupErrors; /** * Represents a single tracked app within the deployment manager. @@ -124,7 +125,9 @@ public class DeploymentManager extends ContainerLifeCycle this.stateTimestamps.put(node, Long.valueOf(System.currentTimeMillis())); } } - + + private MultiException _onStartupErrors; + private Locker _errorLocker = new Locker(); private final List _providers = new ArrayList(); private final AppLifeCycle _lifecycle = new AppLifeCycle(); private final Queue _apps = new ConcurrentLinkedQueue(); @@ -249,9 +252,10 @@ public class DeploymentManager extends ContainerLifeCycle startAppProvider(provider); } - if (onStartupErrors != null) + try (Lock lock = _errorLocker.lock()) { - onStartupErrors.ifExceptionThrow(); + if (_onStartupErrors != null) + _onStartupErrors.ifExceptionThrow(); } super.doStart(); @@ -538,13 +542,15 @@ public class DeploymentManager extends ContainerLifeCycle } } - private synchronized void addOnStartupError(Throwable cause) + private void addOnStartupError(Throwable cause) { - if (onStartupErrors == null) + try (Lock lock = _errorLocker.lock()) { - onStartupErrors = new MultiException(); + if (_onStartupErrors == null) + _onStartupErrors = new MultiException(); + + _onStartupErrors.add(cause); } - onStartupErrors.add(cause); } /**