First executions of delayed and repeating tasks on FoliaAsyncScheduler
run in a single timer thread, making tasks block each other
#12038
Labels
scope: api
status: accepted
Disputed bug is accepted as valid or Feature accepted as desired to be added.
version: 1.21.4
Game version 1.21.4
Expected behavior
Bukkit.getAsyncScheduler().runDelayed(...)
andBukkit.getAsyncScheduler().runAtFixedRate(...)
schedule the task usingFoliaAsyncScheduler#timerThread
: it doesn't matter if it's a delayed or a repeating taskFoliaAsyncScheduler.AsyncScheduledTask#run()
gets run for the taskFoliaAsyncScheduler#executors
Observed/Actual behavior
Bukkit.getAsyncScheduler().runDelayed(...)
andBukkit.getAsyncScheduler().runAtFixedRate(...)
schedule the task usingFoliaAsyncScheduler#timerThread
: it doesn't matter if it's a delayed or a repeating taskFoliaAsyncScheduler.AsyncScheduledTask#run()
gets run for the taskFoliaAsyncScheduler#executors
) but the first one isn't. The work is dispatched into the pool only whenAsyncScheduledTask#state
isSTATE_ON_TIMER
, which is instead alwaysSTATE_SCHEDULED_EXECUTOR
for first runs of all task:AsyncScheduledTask
gets initialized inFoliaAsyncScheduler#scheduleTimerTask(...)
by its constructor: thedelay
argument is alwaysnull
, sothis.state = delay == null ? STATE_SCHEDULED_EXECUTOR : STATE_ON_TIMER
becomesthis.state = STATE_SCHEDULED_EXECUTOR
Paper/paper-server/src/main/java/io/papermc/paper/threadedregions/scheduler/FoliaAsyncScheduler.java
Lines 125 to 128 in a392d47
Paper/paper-server/src/main/java/io/papermc/paper/threadedregions/scheduler/FoliaAsyncScheduler.java
Lines 172 to 180 in a392d47
AsyncScheduledTask#setDelay(ScheduledFuture<?>)
gets called in the same#scheduleTimerTask(...)
method, once again explicitly setting the state:this.state = STATE_SCHEDULED_EXECUTOR
Paper/paper-server/src/main/java/io/papermc/paper/threadedregions/scheduler/FoliaAsyncScheduler.java
Lines 130 to 134 in a392d47
Paper/paper-server/src/main/java/io/papermc/paper/threadedregions/scheduler/FoliaAsyncScheduler.java
Lines 182 to 185 in a392d47
AsyncScheduledTask#run()
is called, the localtimer
variable responsible for dispatching the task into the pool or running it in-place isfalse
, because of the state beingSTATE_SCHEDULED_EXECUTOR
Paper/paper-server/src/main/java/io/papermc/paper/threadedregions/scheduler/FoliaAsyncScheduler.java
Lines 193 to 206 in a392d47
timer
isfalse
, the pool part is skipped and the task is run in-placePaper/paper-server/src/main/java/io/papermc/paper/threadedregions/scheduler/FoliaAsyncScheduler.java
Lines 209 to 217 in a392d47
STATE_FINISHED
, but if it's a repeating task its state finally becomesSTATE_ON_TIMER
, so going back to the 3rd point: during subsequent runstimer
istrue
and the task is properly dispatched into the thread poolSteps/models to reproduce
Expected output:
Observed output:
Plugin and Datapack List
Only the test plugin
Paper version
Other
sorry for way too many letters, hopefully that helps 🎄
The text was updated successfully, but these errors were encountered: