Skip to content

AbstractApplicationEventMulticaster can leak classes [SPR-11606] #16229

Closed

Description

@spring-projects-issues

Eric Bottard opened SPR-11606 and commented

This was discovered as part of the PR mentioned above, in the context of XD.

Basically, we create app contexts which have their own classloaders and can come and go. Those contexts (modules in XD terms) have a parent context that lives longer.
If event listeners are installed in the child context, listening for an event type that is loaded by the custom classloader, the parent context will still retain the types and hence the CL long after the child context has been torn down, preventing proper GC.

This gist https://gist.github.com/ericbottard/ad6da5559257fbcb0325 shows the problem (albeit not using a dedicated classloader). Run it using like yourkit and see retention of the custom event type


Affects: 3.2.8, 4.0.2

Reference URL: spring-attic/spring-xd#669

Issue Links:

Backported to: 3.2.9

Activity

  1. spring-projects-issues commented on Mar 26, 2014

    @spring-projects-issues
    CollaboratorAuthor

    Stéphane Nicoll commented

    When an even is published in the child context, it is also propagated to the parent. The basic publish mechanism first retrieves the listeners that are eligible for that event and cache them if this has not been the case.

    When your sample event is published, the cache of the parent is filled wit a reference to this child event. The problem, as you already mentioned is that ListenerCacheKey holds a reference to a Class and prevents a proper collection of the child context.

    One way of fixing this issue would be to clear this cache when a child context is closed as some child-specific information may have been stored in that cache. I have tried that locally and it works as expected but I still need to figure out if that's the proper way to do it and where.

    Creating your own ApplicationEventMulticaster won't buy you much: at best you could prevent a caching operation if the context in the event is not "your" context but that can prove to be very inefficient.

  2. spring-projects-issues commented on Mar 26, 2014

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

    Fixed with an approach similar to #16145, checking cache safety of the event type and source type before adding them to the cache. To be available in the next 4.0.3 snapshot.

    Juergen

  3. added
    type: bug
    status: backported
    in: core
    on Jan 11, 2019
  4. added this to the 4.0.3 milestone on Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: corestatus: backportedtype: bug

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions