Quartz 2.3.2: Triggers Stuck in ACQUIRED/BLOCKED State
Quartz Version: 2.3.2
All jobs are annotated with @DisallowConcurrentExecution.
The scheduled jobs are running in 2 different instances talking to same DB and isClustered=true.
These instances are EKS pods and there is possibility of PODS going down and gets deployed again. In the past PODS have gone down and got redeployed.
On a customer production system, a number of triggers (some scheduled to run every 30 seconds and others every hour) have stopped firing permanently.
In every case, the corresponding row in QRTZ_TRIGGERS has the following characteristics:
TRIGGER_STATE = ACQUIREDorBLOCKEDNEXT_FIRE_TIMEis frozen at a point in the past (approximately 10 months ago)- There is no matching row in
QRTZ_FIRED_TRIGGERS PREV_FIRE_TIMEis consistent with the frozenNEXT_FIRE_TIME, indicating that the trigger stopped at that point and never advanced again
Meanwhile, the scheduler itself appears to be completely healthy:
- All scheduler nodes continue to check in normally.
QRTZ_SCHEDULER_STATEis current.- Other triggers continue to fire normally and on schedule.
- The issue affects only a subset of triggers.
Impact: The affected triggers remain permanently stuck. Restarting or redeploying the application does not fix the issue.
How is this state possible?
My understanding is that when Quartz acquires a trigger for execution, it performs the following operations:
- Updates
QRTZ_TRIGGERS.TRIGGER_STATEtoACQUIRED. - Inserts the corresponding entry into
QRTZ_FIRED_TRIGGERS. - Both operations occur within the same transaction.
Another possible scenario is that both the update and insert successfully commit, and then the container goes down. In that case, I assume Quartz's recovery/background process on another instance checks QRTZ_SCHEDULER_STATE.LAST_CHECKIN_TIME for each INSTANCE_NAME.
If LAST_CHECKIN_TIME has not been updated within the configured CHECKIN_INTERVAL, Quartz identifies the instance as failed and performs the following recovery operations:
- Deletes the corresponding
INSTANCE_NAMEentry fromQRTZ_SCHEDULER_STATE. - Deletes the associated entries from
QRTZ_FIRED_TRIGGERS. - Updates the corresponding
QRTZ_TRIGGERS.TRIGGER_STATEfromACQUIRED/BLOCKEDback toWAITING. - These recovery operations also occur within the same transaction.
Given this, I am trying to understand how we can end up with a trigger in QRTZ_TRIGGERS where:
TRIGGER_STATE = ACQUIREDorBLOCKEDNEXT_FIRE_TIMEis in the past- and there is no corresponding row in
QRTZ_FIRED_TRIGGERS
This appears to be inconsistent with both the normal trigger-acquisition flow and the Quartz recovery flow described above.
Could you help determine what sequence of events could produce this state in Quartz 2.3.2? In particular, I would like to understand whether there is any legitimate Quartz code path that can leave a trigger permanently in ACQUIRED or BLOCKED with no corresponding QRTZ_FIRED_TRIGGERS row, and under what circumstances this could occur.
Resolution
Based on my analysis, if we update the QRTZ_TRIGGERS.TRIGGER_STATE for all the stuck triggers from ACQUIRED/BLOCKED to WAITING, I believe this should allow Quartz to acquire and execute them again.
Could you please confirm whether this is a safe and appropriate way to recover the affected triggers?
Source: quartz-scheduler/quartz