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:
- Update
registerAddon to return the addon instance.
- Update
onDomContentLoaded to collect these instances.
- Await
Promise.all(instances.map(addon => addon.ready())) to ensure all addons have completed their async initialization.
- Only then call
WorkerManager.onWorkerConstructed.
This guarantees that the registerRemote messages are pushed to the message queue before the loadApplication sequence begins.
Affected File:
A race condition in
Neo.Maincan cause the App Worker to crash ifloadApplicationis sent before all Main Thread addons have registered their remote methods.Root Cause:
registerAddoncreates addon instances, which register their remote methods asynchronously (ininitAsync). However,onDomContentLoadeddoes not wait for this process to complete before signaling that the Main thread is ready (WorkerManager.onWorkerConstructed). This can lead to theloadApplicationmessage (triggered byWorkerManager) arriving at the App Worker before theregisterRemotemessages.Solution: Modify
Neo.Mainto ensure all registered addons are fully initialized (specifically, that they have executedinitAsyncand sent theirregisterRemotemessages) before notifying theWorkerManager.Implementation:
registerAddonto return the addon instance.onDomContentLoadedto collect these instances.Promise.all(instances.map(addon => addon.ready()))to ensure all addons have completed their async initialization.WorkerManager.onWorkerConstructed.This guarantees that the
registerRemotemessages are pushed to the message queue before theloadApplicationsequence begins.Affected File:
src/Main.mjs