Skip to content

fix(coroutines): count MinestomDispatcher delays in ticks - #27

Merged
oglassdev merged 5 commits into
mainfrom
fix/minestom-dispatcher-ticks
Oct 15, 2026
Merged

oglassdev merged 5 commits into
mainfrom
fix/minestom-dispatcher-ticks

Conversation

@oglassdev

Copy link
Copy Markdown
Owner

Summary

  • MinestomDispatcher delays and timeouts now count whole ticks, rounding up (delay(50) = 1 tick, delay(30) = 1 tick, delayTicks(n) = exactly n ticks), and resume on the tick they fire without an extra dispatch hop.
  • Overrides invokeOnTimeout instead of relying on Delay's default method. Previously withTimeout on this dispatcher hung forever when the runtime coroutines version didn't match.
  • Cancelled delays, completed withTimeouts and cancelled Scheduler.awaits release their continuation immediately; Minestom keeps cancelled tasks queued until their tick.
  • Delays beyond MAX_DELAY_TICKS (Int.MAX_VALUE / 2) never fire, instead of overflowing Minestom's int tick deadline and firing immediately.
  • Scheduler.await is now cancellable.
  • The test classpath uses the compiled-against coroutines version (1.11).

Verification

  • Stress harness (not committed): 20 rounds × ~8.5k delays, timeouts, chains and cancellations from multiple threads. Exact tick counts, zero errors.
  • Sol's repros for overflow and retention now pass.

Known limitations (not addressed)

  • Minestom drains at most 4096 ready tasks per tick (JCTools drain default), and cancelled tasks count toward it. Under that load, delays and dispatches slip a tick. Fixing it would mean a KotStom-owned tick queue.
  • Timeouts are tick-based, so a stalled tick thread also stalls timeouts.
  • Off MinestomDispatcher, delayTicks is a wall-clock ticks * 50ms delay.
  • Blocking on the tick thread while waiting for MinestomDispatcher work still deadlocks.

…pending on Delay defaults

Implement every Delay member MinestomDispatcher relies on, so it no
longer calls interface default bodies that only exist in some
kotlinx.coroutines versions (withTimeout hung forever on 1.10.2).
Delays and timeouts are scheduled in whole ticks, rounding up, resume
without an extra tick hop, and release their continuation when
cancelled. Scheduler.await is now cancellable, delayTicks is added, and
tests run against the coroutines version the library compiles with.
…outines

KotStom targets the kotlinx.coroutines version it compiles against.
@oglassdev
oglassdev marked this pull request as ready for review October 15, 2026 00:44
@oglassdev
oglassdev merged commit 36d4ec8 into main Oct 15, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant