Remove spring.event.invoke-listener startup event
Prior to this commit, the `SimpleApplicationEventMulticaster` would be instrumented with the `ApplicationStartup` and start/stop events for invoking event listeners (`spring.event.invoke-listener`). This feature was already limited to single-threaded event publishers, but is still flawed since several types of events can happen concurrently. Due to the single-threaded nature of the startup sequence, our implementation should not produce startup events concurrently. This can cause issues like gh-26057, where concurrent events lead to inconcistencies when tracking parent/child relationships. This commit removes the `spring.event.invoke-listener` startup event as a result. Fixes gh-26057
This commit is contained in:
parent
8f0ad73bfd
commit
4337d8465c
|
|
@ -25,8 +25,6 @@ import org.springframework.beans.factory.BeanFactory;
|
|||
import org.springframework.context.ApplicationEvent;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.core.ResolvableType;
|
||||
import org.springframework.core.metrics.ApplicationStartup;
|
||||
import org.springframework.core.metrics.StartupStep;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.ErrorHandler;
|
||||
|
||||
|
|
@ -57,9 +55,6 @@ public class SimpleApplicationEventMulticaster extends AbstractApplicationEventM
|
|||
@Nullable
|
||||
private ErrorHandler errorHandler;
|
||||
|
||||
@Nullable
|
||||
private ApplicationStartup applicationStartup;
|
||||
|
||||
|
||||
/**
|
||||
* Create a new SimpleApplicationEventMulticaster.
|
||||
|
|
@ -127,22 +122,6 @@ public class SimpleApplicationEventMulticaster extends AbstractApplicationEventM
|
|||
return this.errorHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the {@link ApplicationStartup} to track event listener invocations during startup.
|
||||
* @since 5.3
|
||||
*/
|
||||
public void setApplicationStartup(@Nullable ApplicationStartup applicationStartup) {
|
||||
this.applicationStartup = applicationStartup;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the current application startup for this multicaster.
|
||||
*/
|
||||
@Nullable
|
||||
public ApplicationStartup getApplicationStartup() {
|
||||
return this.applicationStartup;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void multicastEvent(ApplicationEvent event) {
|
||||
multicastEvent(event, resolveDefaultEventType(event));
|
||||
|
|
@ -156,16 +135,6 @@ public class SimpleApplicationEventMulticaster extends AbstractApplicationEventM
|
|||
if (executor != null) {
|
||||
executor.execute(() -> invokeListener(listener, event));
|
||||
}
|
||||
else if (this.applicationStartup != null) {
|
||||
StartupStep invocationStep = this.applicationStartup.start("spring.event.invoke-listener");
|
||||
invokeListener(listener, event);
|
||||
invocationStep.tag("event", event::toString);
|
||||
if (eventType != null) {
|
||||
invocationStep.tag("eventType", eventType::toString);
|
||||
}
|
||||
invocationStep.tag("listener", listener::toString);
|
||||
invocationStep.end();
|
||||
}
|
||||
else {
|
||||
invokeListener(listener, event);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -815,9 +815,7 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader
|
|||
}
|
||||
}
|
||||
else {
|
||||
SimpleApplicationEventMulticaster simpleApplicationEventMulticaster = new SimpleApplicationEventMulticaster(beanFactory);
|
||||
simpleApplicationEventMulticaster.setApplicationStartup(getApplicationStartup());
|
||||
this.applicationEventMulticaster = simpleApplicationEventMulticaster;
|
||||
this.applicationEventMulticaster = new SimpleApplicationEventMulticaster(beanFactory);
|
||||
beanFactory.registerSingleton(APPLICATION_EVENT_MULTICASTER_BEAN_NAME, this.applicationEventMulticaster);
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("No '" + APPLICATION_EVENT_MULTICASTER_BEAN_NAME + "' bean, using " +
|
||||
|
|
|
|||
|
|
@ -1669,8 +1669,4 @@ its behavior changes.
|
|||
| `spring.context.refresh`
|
||||
| Application context refresh phase.
|
||||
|
|
||||
|
||||
| `spring.event.invoke-listener`
|
||||
| Invocation of event listeners, if done in the main thread.
|
||||
| `event` the current application event, `eventType` its type and `listener` the listener processing this event.
|
||||
|===
|
||||
Loading…
Reference in New Issue