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

Deadlock possible with AspectJ aspects and multi-threading

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Complete
    • Affects Version/s: 3.2.16, 4.1.7
    • Fix Version/s: 3.2.17, 4.2.6, 4.3 RC2
    • Component/s: Core:AOP
    • Labels:
      None
    • Last commented by a User:
      true

      Description

      When AspectJ style aspects are used, the aspects are eagerly converted to Spring Advisors, but the AspectJ aspect object is not eagerly created. It is lazily created at the time of its first use. This can be seen in ReflectiveAspectJAdvisorFactory's use of LazySingletonAspectInstanceFacotryDecorator.

      When a singleton Spring bean is created, it grabs the lock of singleton bean map. If, inside its constructor, it calls a function that has an uninitialized aspect wrapped around it, it will then grab the lock in LazySingletonAspectInstanceFactoryDecorator.getAspectInstance.

      If, in a different thread (started after some other bean finishes construction), a call is made that invokes the same aspect, which has not yet been initialized, the lock in LazySingletonAspectInstanceFactoryDecorator.getAspectInstance will be acquired and then the singleton aspect bean will be instantiated. This requires going through the singleton bean instantiation code, which acquires the singleton bean map lock.

      This leads to a deadlock. I've attached a stack trace from jstack of this situation occurring. I think one potential solution would be to eagerly instantiate the singleton AspectJ aspects, not just the advisors that wrap them.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              juergen.hoeller Juergen Hoeller
              Reporter:
              kevinlr5 Kevin Richards
              Last updater:
              Spring Issuemaster
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

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