LearnNewsExamplesServices
Frontmatter
id7815
titleFix race condition: Await addon initialization in Neo.Main
stateClosed
labels
bugrefactoring
assigneestobiu
createdAtNov 19, 2025, 6:06 PM
updatedAtNov 19, 2025, 6:11 PM
githubUrlhttps://github.com/neomjs/neo/issues/7815
authortobiu
commentsCount0
parentIssuenull
subIssues[]
subIssuesCompleted0
subIssuesTotal0
blockedBy[]
blocking[]
closedAtNov 19, 2025, 6:11 PM

Fix race condition: Await addon initialization in Neo.Main

Closed v11.6.1 bugrefactoring
tobiu
tobiu commented on Nov 19, 2025, 6:06 PM

A race condition in Neo.Main can cause the App Worker to crash if loadApplication is sent before all Main Thread addons have registered their remote methods.

Root Cause: registerAddon creates addon instances, which register their remote methods asynchronously (in initAsync). However, onDomContentLoaded does not wait for this process to complete before signaling that the Main thread is ready (WorkerManager.onWorkerConstructed). This can lead to the loadApplication message (triggered by WorkerManager) arriving at the App Worker before the registerRemote messages.

Solution: Modify Neo.Main to ensure all registered addons are fully initialized (specifically, that they have executed initAsync and sent their registerRemote messages) before notifying the WorkerManager.

Implementation:

  1. Update registerAddon to return the addon instance.
  2. Update onDomContentLoaded to collect these instances.
  3. Await Promise.all(instances.map(addon => addon.ready())) to ensure all addons have completed their async initialization.
  4. Only then call WorkerManager.onWorkerConstructed.

This guarantees that the registerRemote messages are pushed to the message queue before the loadApplication sequence begins.

Affected File:

  • src/Main.mjs
tobiu added the bug label on Nov 19, 2025, 6:06 PM
tobiu added the refactoring label on Nov 19, 2025, 6:06 PM
tobiu assigned to @tobiu on Nov 19, 2025, 6:07 PM
tobiu changed title from Fix race condition: Await addon initialization in Neo.main.Main to Fix race condition: Await addon initialization in Neo.Main on Nov 19, 2025, 6:07 PM
tobiu referenced in commit dc48095 - "Fix race condition: Await addon initialization in Neo.Main #7815" on Nov 19, 2025, 6:11 PM
tobiu closed this issue on Nov 19, 2025, 6:11 PM