Ray Milkey
Committed by Gerrit Code Review

Fix shutdown crash if link pruner runs after services are shut down

Change-Id: I7eb3dc9ed19b1a20182d34f8e25df151e32f572f
...@@ -144,6 +144,8 @@ public class LldpLinkProvider extends AbstractProvider implements ProbedLinkProv ...@@ -144,6 +144,8 @@ public class LldpLinkProvider extends AbstractProvider implements ProbedLinkProv
144 144
145 private ScheduledExecutorService executor; 145 private ScheduledExecutorService executor;
146 146
147 + private boolean shuttingDown = false;
148 +
147 // TODO: Add sanity checking for the configurable params based on the delays 149 // TODO: Add sanity checking for the configurable params based on the delays
148 private static final long DEVICE_SYNC_DELAY = 5; 150 private static final long DEVICE_SYNC_DELAY = 5;
149 private static final long LINK_PRUNER_DELAY = 3; 151 private static final long LINK_PRUNER_DELAY = 3;
...@@ -240,6 +242,7 @@ public class LldpLinkProvider extends AbstractProvider implements ProbedLinkProv ...@@ -240,6 +242,7 @@ public class LldpLinkProvider extends AbstractProvider implements ProbedLinkProv
240 242
241 @Activate 243 @Activate
242 public void activate(ComponentContext context) { 244 public void activate(ComponentContext context) {
245 + shuttingDown = false;
243 cfgService.registerProperties(getClass()); 246 cfgService.registerProperties(getClass());
244 appId = coreService.registerApplication(PROVIDER_NAME); 247 appId = coreService.registerApplication(PROVIDER_NAME);
245 248
...@@ -271,6 +274,7 @@ public class LldpLinkProvider extends AbstractProvider implements ProbedLinkProv ...@@ -271,6 +274,7 @@ public class LldpLinkProvider extends AbstractProvider implements ProbedLinkProv
271 274
272 @Deactivate 275 @Deactivate
273 public void deactivate() { 276 public void deactivate() {
277 + shuttingDown = true;
274 cfgRegistry.removeListener(cfgListener); 278 cfgRegistry.removeListener(cfgListener);
275 factories.forEach(cfgRegistry::unregisterConfigFactory); 279 factories.forEach(cfgRegistry::unregisterConfigFactory);
276 280
...@@ -358,7 +362,6 @@ public class LldpLinkProvider extends AbstractProvider implements ProbedLinkProv ...@@ -358,7 +362,6 @@ public class LldpLinkProvider extends AbstractProvider implements ProbedLinkProv
358 deviceService.removeListener(deviceListener); 362 deviceService.removeListener(deviceListener);
359 packetService.removeProcessor(packetProcessor); 363 packetService.removeProcessor(packetProcessor);
360 364
361 -
362 if (executor != null) { 365 if (executor != null) {
363 executor.shutdownNow(); 366 executor.shutdownNow();
364 } 367 }
...@@ -696,7 +699,13 @@ public class LldpLinkProvider extends AbstractProvider implements ProbedLinkProv ...@@ -696,7 +699,13 @@ public class LldpLinkProvider extends AbstractProvider implements ProbedLinkProv
696 699
697 } catch (Exception e) { 700 } catch (Exception e) {
698 // Catch all exceptions to avoid task being suppressed 701 // Catch all exceptions to avoid task being suppressed
702 + if (!shuttingDown) {
703 + // Error condition
699 log.error("Exception thrown during link pruning process", e); 704 log.error("Exception thrown during link pruning process", e);
705 + } else {
706 + // Provider is shutting down, the error can be ignored
707 + log.trace("Shutting down, ignoring error", e);
708 + }
700 } 709 }
701 } 710 }
702 711
......