Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-16901

Inconsistent handling of dependent lifecycle beans in DefaultLifecycleProcessor

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Complete
    • Affects Version/s: 5.0.6
    • Fix Version/s: 5.0.9, 5.1 RC2
    • Component/s: Core
    • Labels:
      None
    • Last commented by a User:
      true

      Description

      DefaultLifecycleProcessor.LifecycleGroup#stop() fails to wait for all members, if there are dependencies between the members.

      IMO the problem lies in this loop of LifecycleGroup#stop():

      for (LifecycleGroupMember member : this.members) {
        if (this.lifecycleBeans.containsKey(member.name)) {
          doStop(this.lifecycleBeans, member.name, latch, countDownBeanNames);
        }
        else if (member.bean instanceof SmartLifecycle) {
          // already removed, must have been a dependent
          latch.countDown();
        }
      }
      

      The loop iterates all members. doStop() removes the current member and its dependent members from this.lifecycleBeans and passes a callback to all of them which counts the latch down. This way the latch gets counted down for the current member and its dependent members.

      Later on when the iteration reaches one of the dependent members from above, the else block gets executed, because the dependent member has already been removed from this.lifecycleBeans. This counts the latch down again for the dependent member.

      This way the latch reaches 0 before all beans called their stop callback and the application context gets destroyed even though some of the members are still running.

      I don't understand why the else block is needed at all. IMO it should be simply removed.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              juergen.hoeller Juergen Hoeller
              Reporter:
              markus_heiden Markus Heiden
              Last updater:
              Spring Issuemaster
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Days since last comment:
                1 year, 40 weeks, 6 days ago