Uploaded image for project: 'Magnolia RSS Aggregator Module'
  1. Magnolia RSS Aggregator Module
  2. MGNLRSSAGG-188

Memory leaks and application hangs created by FastRSSFeedFetcher

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major Major
    • 2.3.3
    • 2.3.1
    • rss_generator

      When the webapplication is shut down during RSS aggregator updates, the Thread pool of FastRSSFeedFetcher is not shut down properly and prevents the application from being shut down properly.

      To fix this, Namics created a method in the ModuleLifecycle to fix this.

      private void shutdownRssFeedFetcher() {
              RSSFeedFetcher fetcher = Components.getComponent(RSSAggregator.class).getFetcher();
              if (fetcher instanceof FastRSSFeedFetcher) {
                  FastRSSFeedFetcher fastFetcher = (FastRSSFeedFetcher) fetcher;
      
                  try {
                      Field executorServiceField = FastRSSFeedFetcher.class.getDeclaredField("executorService");
                      executorServiceField.setAccessible(true);
      
                      Object executorServiceObject = executorServiceField.get(fastFetcher);
      
                      if (executorServiceObject instanceof ExecutorService) {
                          ExecutorService executorService = (ExecutorService) executorServiceObject;
      
                          log.info("Shutting down feed fetcher executor service: " + executorService);
                          List<Runnable> terminated = executorService.shutdownNow();
                          log.info("Cancelled {} Runnable instances.", terminated.size());
      
                          log.info("Terminating feed fetcher executor service: " + executorService);
                          executorService.awaitTermination(5, TimeUnit.MINUTES);
                      }
                  } catch (Throwable e) {
                      log.error("Could not shutdown RSS Feed Fetcher", e);
                  }
      
              }
          }
      

      Of course, it would be nice if the RSSFeedFetcher interface had a stop() method, and the RSSAggregator Module itself would stop it's fetcher.

      To do this, I suggest a method like this:

          public void shutdown() {
              List<Runnable> runnables = executor.shutdownNow();
              log.info("Canceling {} RSS Update Tasks because of shutdown...", runnables.size());
      
              try {
                  if (executor.awaitTermination(5, TimeUnit.MINUTES)) {
                      log.info("Termination successful.");
                  } else {
                      log.error("Termination timed out.");
                  }
              } catch (InterruptedException e) {
                  log.error("Termination error.", e);
              }
          }
      

        Acceptance criteria

              jsimak Jaroslav Simak
              lfischer Lars Fischer
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

                Created:
                Updated:
                Resolved:

                  Bug DoR
                  Task DoD