Skip to content

Fix: Add ALL_MODULES_STARTED fallback for missed DOM_OBJECTS_CREATED#412

Closed
DGessinger wants to merge 1 commit into
Jopyth:masterfrom
DGessinger:fix/dom-objects-created-race-condition
Closed

Fix: Add ALL_MODULES_STARTED fallback for missed DOM_OBJECTS_CREATED#412
DGessinger wants to merge 1 commit into
Jopyth:masterfrom
DGessinger:fix/dom-objects-created-race-condition

Conversation

@DGessinger

Copy link
Copy Markdown

Problem

DOM_OBJECTS_CREATED can occasionally be missed by this module if it fires before
the module has fully registered as a notification listener. This appears to be a
race condition that surfaced with newer Node.js/Electron versions (tested on
Node 22.22.2, MagicMirror 2.37.0, Debian 13). When missed, sendCurrentData() is
never called, this.initialized stays false on the backend forever, and every
API call fails with "Not initialized, have you opened or refreshed your browser...".

Fix

Adds ALL_MODULES_STARTED as a fallback trigger alongside DOM_OBJECTS_CREATED,
since it's received reliably in all tested cases. A currentDataSent flag prevents
sendCurrentData() from running twice if both notifications do arrive.

Testing

Verified on a Raspberry Pi 4B (Debian 13, Node 22.22.2, MagicMirror 2.37.0) where
the original bug reproduced consistently, and the fix resolved it reliably across
multiple restarts.

@KristjanESPERANTO

Copy link
Copy Markdown
Collaborator

Thanks for pointing out this problem and suggesting a solution!
I think we should take a more in-depth look at the architecture here rather than just treating the symptoms. I'll take a closer look at this soon.

KristjanESPERANTO added a commit to KristjanESPERANTO/MMM-Remote-Control that referenced this pull request Jul 3, 2026
Previously the remote API could get stuck as "Not initialized" if the
browser's startup signal was missed, breaking every request until a
manual refresh. It now fetches the current state on demand and answers
the request as soon as the mirror responds.

Ref Jopyth#412
@KristjanESPERANTO

Copy link
Copy Markdown
Collaborator

I ended up fixing it a bit differently: instead of adding a second startup event, the backend now just fetches the current state on demand and answers once the mirror responds - so a missed signal isn't fatal anymore.

Shipped in v5.0.4. Closing this since it's covered, but thanks for finding and pinning it down! 🙏

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.

2 participants