Skip to content

Commit 0533eef

Browse files
Corey Fritzspencergibb
Corey Fritz
authored andcommitted
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.
1 parent c39715b commit 0533eef

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

spring-cloud-commons/src/main/java/org/springframework/cloud/client/discovery/AbstractDiscoveryLifecycle.java

+12-4
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,13 @@
1616

1717
package org.springframework.cloud.client.discovery;
1818

19+
import java.util.concurrent.atomic.AtomicBoolean;
20+
import java.util.concurrent.atomic.AtomicInteger;
21+
1922
import javax.annotation.PreDestroy;
2023

24+
import org.apache.commons.logging.Log;
25+
import org.apache.commons.logging.LogFactory;
2126
import org.springframework.beans.BeansException;
2227
import org.springframework.boot.context.embedded.EmbeddedServletContainerInitializedEvent;
2328
import org.springframework.cloud.client.discovery.event.InstanceRegisteredEvent;
@@ -26,16 +31,15 @@
2631
import org.springframework.context.ApplicationListener;
2732
import org.springframework.core.env.Environment;
2833

29-
import java.util.concurrent.atomic.AtomicBoolean;
30-
import java.util.concurrent.atomic.AtomicInteger;
31-
3234
/**
3335
* Lifecycle methods that may be useful and common to various DiscoveryClient implementations.
3436
* @author Spencer Gibb
3537
*/
3638
public abstract class AbstractDiscoveryLifecycle implements DiscoveryLifecycle,
3739
ApplicationContextAware, ApplicationListener<EmbeddedServletContainerInitializedEvent> {
3840

41+
private static final Log logger = LogFactory.getLog(AbstractDiscoveryLifecycle.class);
42+
3943
private boolean autoStartup = true;
4044

4145
private AtomicBoolean running = new AtomicBoolean(false);
@@ -74,7 +78,11 @@ public boolean isAutoStartup() {
7478

7579
@Override
7680
public void stop(Runnable callback) {
77-
stop();
81+
try {
82+
stop();
83+
} catch (Exception e) {
84+
logger.error("A problem occurred attempting to stop discovery lifecycle", e);
85+
}
7886
callback.run();
7987
}
8088

0 commit comments

Comments
 (0)