Author Topic: Message from node restarts gateway.js  (Read 1951 times)

redpoll123

  • NewMember
  • *
  • Posts: 23
Message from node restarts gateway.js
« on: January 01, 2019, 01:17:21 AM »
I have six identical nodes sending temperature and battery voltage every 6 hours or a message on alarm.
The gateway.js restarts when a message is received from two of the nodes.

Attached is a gateway.sys.log excerpt  with error message that reference  "leakSMSLimiter".

[12-31-18_17:58:07.945] [WARN]   -------> EXCEPTION: nodeId:42 key:leakSMSLimiter JSON: .........

leakSMSLimiter is an event that sends an SMS when the metric changes and it works on the nodes.
I removed the event from all nodes and even deleted the event from the user metric  files and the error with the two nodes still persists.
I suppose something corrupted while building events.
Short of reinstalling gateway, any ideas?

Jason

  • Jr. Member
  • **
  • Posts: 57
Re: Message from node restarts gateway.js
« Reply #1 on: January 01, 2019, 12:33:14 PM »
Are you by chance missing a ‘ mark in your code before nodeId?

From the log
Code: [Select]
> EXCEPTION: nodeId:' + node._id + ' key:' + key + ' JSON: ' + JSON.stringify(node)); throw ex;}

redpoll123

  • NewMember
  • *
  • Posts: 23
Re: Message from node restarts gateway.js
« Reply #2 on: January 01, 2019, 02:25:40 PM »
First I suspected a syntax error, but four out of six nodes do not throw an error.
The event was deleted from the .js file it was in,  so the reference to leakSMSLimiter should not exist.
Yet these two nodes still throw the error which restarts gateway.js.
I'm stumped, which is easy to do.

Jason

  • Jr. Member
  • **
  • Posts: 57
Re: Message from node restarts gateway.js
« Reply #3 on: January 01, 2019, 08:09:03 PM »
Hello,

Is the attached log with the SMS leak event commented out?

You mention 4 work and 2 don’t.  Are 2 wet and 4 dry?

I would also point out this log points to: (/home/pi/gateway/gateway.js:169:17).  This means gateway.js line 169 is where the problem is caught, though the root cause might be farther “upstream”.

Code: [Select]
> EXCEPTION: nodeId:' + node._id + ' key:' + key + ' JSON: ' + JSON.stringify(node)); throw ex;}
                                                                                                                            ^

TypeError: Cannot read property 'serverExecute' of undefined
    at global.handleNodeEvents (/home/pi/gateway/gateway.js:169:17)
    at /home/pi/gateway/gateway.js:593:9
    at newArguments.(anonymous function)



Thanks,
Jason
« Last Edit: January 01, 2019, 08:15:07 PM by Jason »

redpoll123

  • NewMember
  • *
  • Posts: 23
Re: Message from node restarts gateway.js
« Reply #4 on: January 02, 2019, 10:58:23 AM »
>>>>Is the attached log with the SMS leak event commented out?

Commented out the event first then deleted it from file, both cases the reference to the event still shows in the error.

>>>>>You mention 4 work and 2 don’t.  Are 2 wet and 4 dry?

These nodes are water leak detectors.
The nodes send battery/temperature every 6 hours along with alarm status which if there is no water sends  "DRY".
If water then the node wakes up and sends "WET" with battery/temperature.

To get an immediate message from a node I simulate a leak(short contacts), so the log entry will show "WET".

I also noticed the pointing to gateway.js so downloaded it and did a diff on the files - no differences.
I have another gateway/raspberry so I tryed one of the "cranky" nodes on that - no errors worked OK there.
 

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6867
  • Country: us
    • LowPowerLab
Re: Message from node restarts gateway.js
« Reply #5 on: January 02, 2019, 11:49:26 AM »
The problem is on line 168 and 169:
Code: [Select]
        var evt = metricsDef.events[key];
        if (evt.serverExecute!=undefined)
The code assumes you have an event defined, and that has a serverExecute event defined.

What does your metrics.js file diff look like? (Or the file where leakSMSLimiter  is defined)

redpoll123

  • NewMember
  • *
  • Posts: 23
Re: Message from node restarts gateway.js
« Reply #6 on: January 03, 2019, 10:10:01 PM »
>>>>>>The code assumes you have an event defined, and that has a serverExecute event defined.

>>>>>> What does your metrics.js file diff look like? (Or the file where leakSMSLimiter  is defined)


The strange thing it is not defined anywhere?

It was deleted from the .js file. - Still threw an error

I grepped all the .js files in gateway and in userMetrics for the string leakSMSLimiter - not there.

The metrics.js file is identical to the one on lowpowerlab github.

Even if this event still existed why/how do only these two nodes call an event that has not been added to their list.
At present none of the nodes on the gateway have an event of any kind, yet for these two nodes leakSMSLimiter is called.

Almost ready to reinstall the gateway, but it would be nice to know how I broke it!

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6867
  • Country: us
    • LowPowerLab
Re: Message from node restarts gateway.js
« Reply #7 on: January 04, 2019, 10:15:53 AM »
You need to find what this mistery leakSMSLimiter is ;), nothing like that in my released code  :-\

redpoll123

  • NewMember
  • *
  • Posts: 23
Re: Message from node restarts gateway.js
« Reply #8 on: January 04, 2019, 11:54:41 AM »
Like Dr. Frankenstein I created something that assumed a life of it's own.

Nice to know what is the cause, but have a problem and can't repair it, save time and effort replace it.

Thanks,
Tony


 

redpoll123

  • NewMember
  • *
  • Posts: 23
Re: Message from node restarts gateway.js
« Reply #9 on: January 06, 2019, 12:45:05 AM »
Solved the case of the mystery event.

Adding an event to a node appends a line, with node info, to the database file gateway.db.
The event is in the line and shows enabled.

Removing an event from a node appends a node info line to the gateway.db file.
The event is not in the line.
 

How to create a mystery event.

While the event is still enabled in the node(s) -
delete/remove the event from its location in the metric.js file or other .js file in userMetric.

Restart the gateway.

The database gateway.db still contains the event as enabled for the node(s) even though it no longer exists.

The gateway receives a message from the node(s), the database shows the event as enabled, an attempt to
execute the event is done and it fails as undefined because it does not exist.

To clear the problem -
Delete the gateway.db file which is recreated (or edit it so the nodes don't have to be set up).


Order while destroying events -

1. Remove the event from all nodes, this updates the database.
2. Then delete the event from the file it is in.

Jason

  • Jr. Member
  • **
  • Posts: 57
Re: Message from node restarts gateway.js
« Reply #10 on: January 06, 2019, 12:18:03 PM »
Thanks for taking the time to post the solution!  Good to know how to remove events!

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6867
  • Country: us
    • LowPowerLab
Re: Message from node restarts gateway.js
« Reply #11 on: January 06, 2019, 05:53:21 PM »
I actually ran into this myself, just haven't connected the dots when you posted this thread.
An orphaned even can exist in the db node instance, and be "enabled" causing it to try to fire, but since there's no longer code for it, it will not show in the UI and will fail when it should run.
So ... maybe this can be some kind of fix upon startup, to check events integrity.
Thanks for reporting back.