Skip to content

Fix EventLoopScheduler startup idle tracking race - #136

Open
Dongnyoung wants to merge 3 commits into
franz1981:masterfrom
Dongnyoung:fix/scheduler-startup-idle-race
Open

Fix EventLoopScheduler startup idle tracking race#136
Dongnyoung wants to merge 3 commits into
franz1981:masterfrom
Dongnyoung:fix/scheduler-startup-idle-race

Conversation

@Dongnyoung

Copy link
Copy Markdown

Summary

Fixes a startup race where EventLoopScheduler could start its carrier thread before ClusterState was connected.

Before this change, the carrier thread was started inside the EventLoopScheduler constructor. This allowed the carrier loop to reach tryPark() while clusterState == null, transition carrierState to PARKED, and skip markIdle(id).

If ClusterState was connected afterward, the carrier could remain parked while being absent from IdleCarrierTracker, preventing wakeFirstIdle(...) from discovering it.

Changes

  • Stop starting the carrier thread from the EventLoopScheduler constructor.
  • Add package-private startCarrier() for controlled startup.
  • Start all carriers from EventLoopSchedulerGroup only after:
    • ClusterState is assigned
    • group is assigned
    • work-stealing siblings are assigned
  • Add a regression test for the startup idle-discoverability invariant.

This also ensures that the scheduler wiring performed before Thread.start() is published to the carrier thread through the Thread.start() happens-before relationship.

Invariant Covered

If a carrier is PARKED and connected to ClusterState, it must be discoverable through IdleCarrierTracker / wakeFirstIdle(...).

The regression test connects the scheduler to ClusterState before starting its carrier, waits until the carrier actually parks, and verifies that wakeFirstIdle(...) can discover it as idle.

Testing

  • git diff --check
  • Loom Build Tests GitHub Actions workflow passed on the fork.

Local Maven execution was not possible because the available local JDK does not provide the Java 28 APIs required by the project.

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