Uploaded image for project: 'ModeShape'
  1. ModeShape
  2. MODE-2343

Run-away threads when using the JCR ObservationManager

    XMLWordPrintable

Details

    Description

      In our application, we're seeing run-away threads when using the ObservationManager. Our application creates a new session for every HTTP request, and uses the ObservationManager to register some contextual data. When we invoke Workspace#getObservationManager, it appears that we create a new modeshape-event-dispatcher thread that is not disposed off when Session#logout is called.

      Not that this is a very good demo, but I hope it gets the point across:

          @Test
          @FixFor("MODE-xxxx")
          public void shouldNotLeakObservers() throws Exception {
              final int oldCount = Thread.activeCount();
              for (int i = 0; i < 1000; i++) {
                  final Session newSession = newSession();
                  newSession.getWorkspace().getObservationManager();
                  newSession.logout();
              }
              final int newCount = Thread.activeCount();
      
              assertEquals(oldCount, newCount);
              /* After running the test, these counts are ~1000 different */
          }
      

      Digging into the code, I suspect (though haven't confirmed) that the ObservationManager's own listener is not removed:

      https://github.com/ModeShape/modeshape/blob/master/modeshape-jcr/src/main/java/org/modeshape/jcr/JcrObservationManager.java#L174

      Attachments

        Issue Links

          Activity

            People

              hchiorean Horia Chiorean (Inactive)
              cbeer_jira Chris Beer (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: