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

Process cannot exit when the SchedulerFactoryBean fails to initialize [SPR-16816] #21356

Closed
spring-issuemaster opened this Issue May 12, 2018 · 2 comments

Comments

Projects
None yet
2 participants
@spring-issuemaster
Copy link
Collaborator

spring-issuemaster commented May 12, 2018

ScienJus opened SPR-16816 and commented

For some reason, there is an occasional exception arise from database queries when using quartz's cluster mode. when this exception occurs, the Spring container will close and exit, leaving Java Process suspending.

Through the jstack logs I found that some quartz threads are still running. because they are user threads, the Java process does not exit.

The threads are supposed to close through the destroy method in SchedulerFactoryBean, but unfortunately, if an exception is thrown in afterPropertiesSet, the destroy method will not be called, subsequently, these threads will not be closed in the meanwhile.

Here are the jstack logs and error logs. You can see that registerJobsAndTriggers throws an exception after the scheduler started. So I prepare to catch the invokation of the method and manually call the destroy method when it throwing an exception.

Caused by: org.quartz.JobPersistenceException: Couldn't retrieve trigger: No record found for selection of Trigger with key: 'DEFAULT.bikeLowPowerUpcomingJobTrigger' and statement: SELECT * FROM QRTZ_CRON_TRIGGERS WHERE SCHED_NAME = 'molaQuartzScheduler' AND TRIGGER_NAME = ? AND TRIGGER_GROUP = ?    at org.quartz.impl.jdbcjobstore.JobStoreSupport.retrieveTrigger(JobStoreSupport.java:1533)    at org.quartz.impl.jdbcjobstore.JobStoreSupport$12.execute(JobStoreSupport.java:1522)    at org.quartz.impl.jdbcjobstore.JobStoreCMT.executeInLock(JobStoreCMT.java:245)    at org.quartz.impl.jdbcjobstore.JobStoreSupport.executeWithoutLock(JobStoreSupport.java:3739)    at org.quartz.impl.jdbcjobstore.JobStoreSupport.retrieveTrigger(JobStoreSupport.java:1519)    at org.quartz.core.QuartzScheduler.getTrigger(QuartzScheduler.java:1530)    at org.quartz.impl.StdScheduler.getTrigger(StdScheduler.java:508)    at org.springframework.scheduling.quartz.SchedulerAccessor.addTriggerToScheduler(SchedulerAccessor.java:291)    at org.springframework.scheduling.quartz.SchedulerAccessor.registerJobsAndTriggers(SchedulerAccessor.java:235)    at org.springframework.scheduling.quartz.SchedulerFactoryBean.afterPropertiesSet(SchedulerFactoryBean.java:510)

I‘d like to create a pull request if you agree with this solution.


Affects: 4.3.17, 5.0.6

Attachments:

Referenced from: pull request #1828, and commits 849b6cc, 0098245, a3bcdbe

Backported to: 4.3.18

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

spring-issuemaster commented May 13, 2018

ScienJus commented

hi @Juergen Hoeller , have you started working on it?If not, i wish to get it done.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

spring-issuemaster commented May 15, 2018

Juergen Hoeller commented

I ended up refactoring SchedulerFactoryBean a bit further, wrapping Scheduler initialization through a delegate and locally shutting down the Scheduler in afterPropertiesSet if necessary (since destroy() is only really meant for external lifecycle destruction signals).

This is on master now; I'll backport it to 5.0.x and 4.3.x tomorrow, along with a few other changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment