Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ApplicationEventPublisher - PayloadApplicationEvent not received by EventListener if event fired from child context #30360

Closed
robtha opened this issue Apr 20, 2023 · 3 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: regression A bug that is also a regression
Milestone

Comments

@robtha
Copy link

robtha commented Apr 20, 2023

If PayloadApplicationEvent is published via ApplicationEventPublisher from child context, it will not be received by EventListeners in the parent context. This worked in Spring 5.x

Tested with spring versions: 6.0.7, 6.0.8

I have attached a sample application to reproduce the problem.

PayloadApplicationEventS are only received by the EventListener in the child context but not in parent context.
Subclasses of ApplicationEvent are not affected and still received by the listener in the parent context.

kind regards
Robert

sample.zip

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Apr 20, 2023
@sbrannen sbrannen added the in: core Issues in core modules (aop, beans, core, context, expression) label Apr 20, 2023
@simonbasle simonbasle self-assigned this May 2, 2023
@simonbasle simonbasle added type: bug A general bug type: regression A bug that is also a regression and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels May 3, 2023
@simonbasle simonbasle added this to the 6.0.9 milestone May 3, 2023
@simonbasle
Copy link
Contributor

This is indeed a regression linked to #24599

@simonbasle simonbasle added the status: superseded An issue that has been superseded by another label May 4, 2023
@simonbasle
Copy link
Contributor

Superseded by PR gh-30420.

@simonbasle simonbasle closed this as not planned Won't fix, can't repro, duplicate, stale May 4, 2023
simonbasle added a commit to simonbasle/spring-framework that referenced this issue May 4, 2023
This commit introduces a more defensive propagation of an event
and the optionally associated eventType when calling `publishEvent`,
especially when a parent context is present.

Notably, it avoids a situation where the parent `publishEvent` call
would generate a new `PayloadApplicationEvent` with the wrong eventType
(`PayloadApplicationEvent<PayloadApplicationEvent<T>>`).

This commit also adds test coverage (which includes cases where an event
is fired before the multicaster is set) and a defensive check against
inconsistent publishing of a PayloadApplicationEvent (even though that
is something that is expected to be done mostly internally by the
framework).

Closes spring-projectsgh-30360
@jhoeller jhoeller removed the type: bug A general bug label May 10, 2023
@jhoeller
Copy link
Contributor

We eventually decided to introduce a focused revision for addressing this regression, consistently pre-resolving event types vs payload types now.

@jhoeller jhoeller reopened this May 10, 2023
@jhoeller jhoeller removed the status: superseded An issue that has been superseded by another label May 10, 2023
@jhoeller jhoeller self-assigned this May 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: regression A bug that is also a regression
Projects
None yet
Development

No branches or pull requests

5 participants