enhancement
major
minor
defect
critical
major
minor
major
#30123
The scheduler incorrectly reports "There is no thread to remove" when a task fails to start
Problem
If a task fails to start before its thread has been created, the scheduler writes a misleading error message to the log in addition to the actual error:
ERROR ... SchedulerEntry There is no thread to remove. SchedulerEntry(task = '...RefreshUsersTask...', state = STARTING, thread = 'null', ...)
java.lang.IllegalStateException: There is no thread to remove. ...
at com.top_logic.util.sched.entry.SchedulerEntry.removeThread(SchedulerEntry.java)
at com.top_logic.util.sched.Scheduler.ensureActiveOrScheduled(Scheduler.java)
at com.top_logic.util.sched.Scheduler.tryStartTask(Scheduler.java)
...
This was observed in a production system when `Scheduler.requestClusterLock ` failed during commit with a ` KnowledgeBaseRuntimeException ` ("Commit aborted in response to long-running concurrent refetch.").
Cause
Scheduler.tryStartTask catches errors that occur when starting a task and calls ensureActiveOrScheduled. For an entry in the STARTING state, this method always calls SchedulerEntry.removeThread(). However, the thread is not created until ` startTaskNow` is called. If the start fails beforehand—for example, when requesting the cluster lock, during the maintenance mode check, or due to the task log—there is no thread, and `removeThread()` reports an error.
Solution
`ensureActiveOrScheduled` now removes the thread in the STARTING state only if one exists. The second caller of `removeThread()`, `Scheduler.taskDone`, remains unchanged. It is called only for entries in the RUNNING state, and those always have a thread.