From 36e8d7e3b952aca7c31df74f513e4aa476e7512c Mon Sep 17 00:00:00 2001 From: Arunan Sugunakumar Date: Fri, 15 Mar 2024 16:27:32 +0530 Subject: [PATCH] Improve StartupController to delete pending tasks When the TaskScheduler is initialized but TaskManager is not initialized, the task will be added to taskQueue. But when the task gets destroyed before the tTaskManager is not initialized, the taskQueue is not cleared. Resolves wso2/api-manager#2525 --- .../apache/synapse/startup/quartz/StartUpController.java | 2 +- .../main/java/org/apache/synapse/task/TaskScheduler.java | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/modules/core/src/main/java/org/apache/synapse/startup/quartz/StartUpController.java b/modules/core/src/main/java/org/apache/synapse/startup/quartz/StartUpController.java index c0bfefc43e..2d30e2b169 100644 --- a/modules/core/src/main/java/org/apache/synapse/startup/quartz/StartUpController.java +++ b/modules/core/src/main/java/org/apache/synapse/startup/quartz/StartUpController.java @@ -76,7 +76,7 @@ public void destroy(boolean removeTask) { } if (synapseTaskManager.isInitialized()) { TaskScheduler taskScheduler = synapseTaskManager.getTaskScheduler(); - if (taskScheduler != null && taskScheduler.isInitialized() && removeTask) { + if (taskScheduler != null && taskScheduler.isTaskSchedulerInitialized() && removeTask) { taskScheduler.deleteTask(taskDescription.getName(), taskDescription.getTaskGroup()); } TaskDescriptionRepository repository = synapseTaskManager.getTaskDescriptionRepository(); diff --git a/modules/tasks/src/main/java/org/apache/synapse/task/TaskScheduler.java b/modules/tasks/src/main/java/org/apache/synapse/task/TaskScheduler.java index eccea36447..701d7fa87a 100644 --- a/modules/tasks/src/main/java/org/apache/synapse/task/TaskScheduler.java +++ b/modules/tasks/src/main/java/org/apache/synapse/task/TaskScheduler.java @@ -159,6 +159,12 @@ public boolean isInitialized() { } } + public boolean isTaskSchedulerInitialized() { + synchronized (lock) { + return initialized; + } + } + public void deleteTask(String name, String group) { synchronized (lock) { if (!initialized) {