Catch and log exceptions that occur when attempting to deregister a service during shutdown.
Currently, if an exception is thrown when deregistering the service (maybe the registry is not available) the latch used by the DefaultLifecycleProcessor is not decremented and you have to wait for the latch timeout (30 seconds) for shutdown to complete. With this fix, the exception is logged and normal shutdown execution continues.
This commit is contained in:
committed by
Spencer Gibb
parent
c39715b9f6
commit
0533eef471
@@ -16,8 +16,13 @@
|
||||
|
||||
package org.springframework.cloud.client.discovery;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import javax.annotation.PreDestroy;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.boot.context.embedded.EmbeddedServletContainerInitializedEvent;
|
||||
import org.springframework.cloud.client.discovery.event.InstanceRegisteredEvent;
|
||||
@@ -26,9 +31,6 @@ import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/**
|
||||
* Lifecycle methods that may be useful and common to various DiscoveryClient implementations.
|
||||
* @author Spencer Gibb
|
||||
@@ -36,6 +38,8 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
public abstract class AbstractDiscoveryLifecycle implements DiscoveryLifecycle,
|
||||
ApplicationContextAware, ApplicationListener<EmbeddedServletContainerInitializedEvent> {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(AbstractDiscoveryLifecycle.class);
|
||||
|
||||
private boolean autoStartup = true;
|
||||
|
||||
private AtomicBoolean running = new AtomicBoolean(false);
|
||||
@@ -74,7 +78,11 @@ public abstract class AbstractDiscoveryLifecycle implements DiscoveryLifecycle,
|
||||
|
||||
@Override
|
||||
public void stop(Runnable callback) {
|
||||
stop();
|
||||
try {
|
||||
stop();
|
||||
} catch (Exception e) {
|
||||
logger.error("A problem occurred attempting to stop discovery lifecycle", e);
|
||||
}
|
||||
callback.run();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user