question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

sendSocketNotification send twice from node_helper

See original GitHub issue

Hardware: Raspberry Pi 4 Magic Mirror version: 2.14.0 Node version: 10.23.1

Problem: It seems that the node_helper processes a socket notification twice. This goes for all modules I installed that have a node_helper. I added some logging to the .js of the module itself and to the node_helper. It just sends a socket notification to the helper and the helper sends it back. While the socket notification to the helper is send once, the helper sends 2 socket notifications back.

.js of the module. The getData function is called by the scheduled interval every 10 seconds.

getData: function(url) {
  self = this;
  var requestData = new XMLHttpRequest();
  requestData.onreadystatechange = function() {
    if (this.readyState === 4) {
      if (this.status === 200) {
        console.log("Send notification");
        self.sendSocketNotification("MMM-DOMO-DATA-LOADED", { data: JSON.parse(this.responseText) } );
      } else {
        Log.error(self.name + ": Could not load data.");
        console.log("Did not load data");
      }
    };
  }
  requestData.open("GET", url, true);
  requestData.send();
},

node_helper:

socketNotificationReceived: function (notification, payload) {
  self = this;
  if ( notification == "MMM-DOMO-DATA-LOADED") {
    console.log("Send back");
    self.sendSocketNotification("MMM-DOMO-DATA-RECEIVED", payload.data);
  }
},

The logging shows: [21.01.2021 20:05.11.989] [LOG] Send notification [21.01.2021 20:05.12.228] [LOG] Send back [21.01.2021 20:05.12.547] [LOG] Send back

So somehow the notification that is send to the helper is received and processed twice. Any suggestion how to prevent this from happening? Or am I missing something? This module is the only module in the config.json.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
goedh452commented, Jan 22, 2021

Thanks for your response! I tested it and in the process found my mistake. Normally I code and test directly on the mirror itself, but the past few days I tested it in a browser on the laptop. However, the mirror itself is also operational, so basically there are 2 clients. Both send 1 notification to the helper and the helper (of course) processes both and thus sends 2 notifications back. Now I run MM in server mode and everything is fine.

I appreciate you both took the time to look into this and will continu to support the project!

0reactions
khasselcommented, Jan 21, 2021

tried to debug this with the default/newsfeed module.

Results:

  • at the first time loading mm in the browser the event is only logged once in the server logs
  • waiting for the next regular reload interval the event is only logged once in the server logs
  • refreshing the browser the event is logged twice in the server logs

AFAIK this is expected behaviour because when refreshing the browser the server side callback function is called explicitly when getting the fetcher and in the normal way.

Tested this also with v2.13.0, same behaviour.

@goedh452 can you confirm the result above? If not can you provide a module example?

Read more comments on GitHub >

github_iconTop Results From Across the Web

turning monitor on by incoming call? - MagicMirror Forum
My best bet is that you need to either send directly the SCREEN_WAKEUP socketNotification from MMM-PIR-Sensor.js to node.helper.js or send a ...
Read more >
Python not receiving pyshell.send message... sometimes
So NOW it's working like I want it to. EDIT: AGAIN: Not sure what happened but that stopped working. So I put the...
Read more >
javascript - Smart Mirror Project - WordPress.com
Inside the node helper of the MMM-infodisplay I created a new ... notification in the sendSocketNotification function sending the info back ...
Read more >
“Magic Mirror” - Capstone Projects
To fix this issue the team had to purchase new pieces and once again took the measurements required to ... Send a socket...
Read more >
Interactive Information Console for Atwater Kent - Digital WPI
to an LED display sending card which communicates with the LED display receiving ... appeared again. ... Requests node helper to add calendar...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found