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

Event handling in JobExecutionExitCodeGenerator is not thread-safe #30705

Closed
wants to merge 2 commits into from

Conversation

dugenkui03
Copy link
Contributor

@dugenkui03 dugenkui03 commented Apr 16, 2022

The listener could be invoked concurrently by multiple thread, we should make them threadsafe.

SimpleApplicationEventMulticaster doc:

By default, all listeners are invoked in the calling thread.

…herTests, HibernateJpaAutoConfigurationTests threadsafe
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Apr 16, 2022
Copy link
Member

@wilkinsona wilkinsona left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks very much for the PR, @dugenkui03. While I think the change to ClassPathFileSystemWatcherTests is worth making, I'd like to focus on JobExecutionExitCodeGenerator as that's a bug in main code.

@@ -600,7 +600,7 @@ EventCapturingApplicationListener jpaUsingApplicationListener(EntityManagerFacto

static class EventCapturingApplicationListener implements ApplicationListener<ApplicationEvent> {

private final List<ApplicationEvent> events = new ArrayList<>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this change is necessary. Within the context of the two tests that use the listener, events are only ever delivered on the main thread.

@@ -116,7 +117,7 @@ Listener listener() {

static class Listener implements ApplicationListener<ClassPathChangedEvent> {

private List<ClassPathChangedEvent> events = new ArrayList<>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@@ -31,7 +31,7 @@
*/
public class JobExecutionExitCodeGenerator implements ApplicationListener<JobExecutionEvent>, ExitCodeGenerator {

private final List<JobExecution> executions = new ArrayList<>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 This could also break with a single-threaded event multi-caster if getExitCode() is called one one thread when another thread is delivering an event.

@dugenkui03
Copy link
Contributor Author

@wilkinsona Thanks for your review. Code in HibernateJpaAutoConfigurationTests have been reverted , please help review again.

@wilkinsona wilkinsona changed the title Make ConditionEvaluationDeltaLoggingListener, ClassPathFileSystemWatcherTests, HibernateJpaAutoConfigurationTests threadsafe Event handling in JobExecutionExitCodeGenerator is not thread-safe May 3, 2022
@wilkinsona wilkinsona added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels May 3, 2022
@wilkinsona wilkinsona added this to the 2.5.x milestone May 3, 2022
@wilkinsona wilkinsona closed this in e08483f May 3, 2022
@wilkinsona
Copy link
Member

Thanks very much, @dugenkui03. I separated out into a separate issue (#30844) the changes to ClassPathFileSystemWatcherTests as, unlike the problem with JobExecutionExitCodeGenereator, the problem with the tests won't affect users.

@wilkinsona wilkinsona modified the milestones: 2.5.x, 2.5.14 May 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants