Fix shutdown crash if link pruner runs after services are shut down
Change-Id: I7eb3dc9ed19b1a20182d34f8e25df151e32f572f
Showing
1 changed file
with
11 additions
and
2 deletions
... | @@ -142,6 +142,8 @@ public class LldpLinkProvider extends AbstractProvider implements ProbedLinkProv | ... | @@ -142,6 +142,8 @@ public class LldpLinkProvider extends AbstractProvider implements ProbedLinkProv |
142 | 142 | ||
143 | private ScheduledExecutorService executor; | 143 | private ScheduledExecutorService executor; |
144 | 144 | ||
145 | + private boolean shuttingDown = false; | ||
146 | + | ||
145 | // TODO: Add sanity checking for the configurable params based on the delays | 147 | // TODO: Add sanity checking for the configurable params based on the delays |
146 | private static final long DEVICE_SYNC_DELAY = 5; | 148 | private static final long DEVICE_SYNC_DELAY = 5; |
147 | private static final long LINK_PRUNER_DELAY = 3; | 149 | private static final long LINK_PRUNER_DELAY = 3; |
... | @@ -238,6 +240,7 @@ public class LldpLinkProvider extends AbstractProvider implements ProbedLinkProv | ... | @@ -238,6 +240,7 @@ public class LldpLinkProvider extends AbstractProvider implements ProbedLinkProv |
238 | 240 | ||
239 | @Activate | 241 | @Activate |
240 | public void activate(ComponentContext context) { | 242 | public void activate(ComponentContext context) { |
243 | + shuttingDown = false; | ||
241 | cfgService.registerProperties(getClass()); | 244 | cfgService.registerProperties(getClass()); |
242 | appId = coreService.registerApplication(PROVIDER_NAME); | 245 | appId = coreService.registerApplication(PROVIDER_NAME); |
243 | 246 | ||
... | @@ -265,6 +268,7 @@ public class LldpLinkProvider extends AbstractProvider implements ProbedLinkProv | ... | @@ -265,6 +268,7 @@ public class LldpLinkProvider extends AbstractProvider implements ProbedLinkProv |
265 | 268 | ||
266 | @Deactivate | 269 | @Deactivate |
267 | public void deactivate() { | 270 | public void deactivate() { |
271 | + shuttingDown = true; | ||
268 | cfgRegistry.removeListener(cfgListener); | 272 | cfgRegistry.removeListener(cfgListener); |
269 | factories.forEach(cfgRegistry::unregisterConfigFactory); | 273 | factories.forEach(cfgRegistry::unregisterConfigFactory); |
270 | 274 | ||
... | @@ -352,7 +356,6 @@ public class LldpLinkProvider extends AbstractProvider implements ProbedLinkProv | ... | @@ -352,7 +356,6 @@ public class LldpLinkProvider extends AbstractProvider implements ProbedLinkProv |
352 | deviceService.removeListener(deviceListener); | 356 | deviceService.removeListener(deviceListener); |
353 | packetService.removeProcessor(packetProcessor); | 357 | packetService.removeProcessor(packetProcessor); |
354 | 358 | ||
355 | - | ||
356 | if (executor != null) { | 359 | if (executor != null) { |
357 | executor.shutdownNow(); | 360 | executor.shutdownNow(); |
358 | } | 361 | } |
... | @@ -690,7 +693,13 @@ public class LldpLinkProvider extends AbstractProvider implements ProbedLinkProv | ... | @@ -690,7 +693,13 @@ public class LldpLinkProvider extends AbstractProvider implements ProbedLinkProv |
690 | 693 | ||
691 | } catch (Exception e) { | 694 | } catch (Exception e) { |
692 | // Catch all exceptions to avoid task being suppressed | 695 | // Catch all exceptions to avoid task being suppressed |
693 | - log.error("Exception thrown during link pruning process", e); | 696 | + if (!shuttingDown) { |
697 | + // Error condition | ||
698 | + log.error("Exception thrown during link pruning process", e); | ||
699 | + } else { | ||
700 | + // Provider is shutting down, the error can be ignored | ||
701 | + log.trace("Shutting down, ignoring error", e); | ||
702 | + } | ||
694 | } | 703 | } |
695 | } | 704 | } |
696 | 705 | ... | ... |
-
Please register or login to post a comment