tagyoureit / nodejs-poolController

An application to control pool equipment from various manufacturers.
GNU Affero General Public License v3.0
323 stars 94 forks source link

[BUG] "Maximum Call Stack Size Exceeded" error at poolController startup #703

Closed jwtaylor310 closed 1 year ago

jwtaylor310 commented 1 year ago

nodejs-poolController Version/commit

8.0.0/cb05840

nodejs-poolController-dashPanel Version/commit

8.0.0/cb05840

relayEquipmentManager Version/commit

Not Applicable

Node Version

v19.8.1

Platform

Linux raspberrypi 5.15.84-v8+ #1613 SMP PREEMPT Thu Jan 5 12:03:08 GMT 2023 aarch64 GNU/Linux

RS485 Adapter

Elfin

Are you using Docker?

OCP

EasyTouch2

Pump(s)

No response

Chlorinator(s)

Intellichlor-40

What steps will reproduce the bug?

Run "npm start" in nodejs-poolController folder.

What happens?

While getting equipment list the program reports "RangeError: Maximum call stack size exceeded" and the program exits.

Terminal display prior at program exit:

[3/16/2023, 9:13:39 AM] verbose: Config Queue Completed... 88% (7 remaining) [3/16/2023, 9:13:39 AM] debug: Assigning message id 109 [3/16/2023, 9:13:39 AM] info: {"port":0,"id":109,"valid":true,"dir":"out","proto":"broadcast","pkt":[[],[255,0,255], [165,30,16,33,214,1], [0],[1,203]],"ts":"2023-03-16T09:13:39.198-0400"} [3/16/2023, 9:13:39 AM] verbose: Wrote packet [Port 0 id: 109] [255,0,255,165,30,16,33,214,1,0,1,203].Retries remaining: 3 [3/16/2023, 9:13:39 AM] debug: Assigning message id 110

/home/pi/nodejs-poolController/controller/Equipment.ts:1401 public getNextEquipmentId(range?: EquipmentIdRange, exclude?: number[]): number { return this.getNextEquipmentId(typeof range === 'undefined' ? sys.board.equipmentIds.pumps : range, exclude); } ^ RangeError: Maximum call stack size exceeded at PumpCollection.getNextEquipmentId (/home/pi/nodejs-poolController/controller/Equipment.ts:1401:99) at PumpCollection.getNextEquipmentId (/home/pi/nodejs-poolController/controller/Equipment.ts:1401:99) at PumpCollection.getNextEquipmentId (/home/pi/nodejs-poolController/controller/Equipment.ts:1401:99) (Repeats 'at PumpCollection' message 16 times before exiting)

What should have happened?

Normal startup of pool controller

Additional information

This is a new install of version 8.0.0 on a Raspberry Pi. The first time the system was started it defaulted to a Local RS485 connection and the controller started normally but, as expected, reported communication failures. In DashPanel I changed the Comms to "Network" and provided the IP address and port number of the Elfin RS485-Ethernet adapter. The system then established communications and tried to load the equipment configuration. After reporting 88% completion the program exited with the error "RangeError: Maximum call stack size exceeded". Subsequent reboots and attempts to start the controller fail with the RangeError message.

Here's the replay file: Replay File.txt

rstrouse commented 1 year ago

Thanks, I found a place where we could get into a circular reference looking for valid equipment ids. Pull njsPC. Also, in the future, the replay file that you provided really doesn't tell me much. I did manage to find another replay that had similar equipment and managed to get it to fail.

jwtaylor310 commented 1 year ago

Thanks for the quick response. The update fixed my 'call stack size exceeded' error and the controller program now starts up without a problem. However, when I try to turn on/off a feature in the web interface I am now getting the following:

MessageCannot read properties of undefined (reading 'setCircuitStateAsync') TypeError: Cannot read properties of undefined (reading 'setCircuitStateAsync') at SLCircuits.setCircuitStateAsync (/home/pi/nodejs-poolController/controller/comms/ScreenLogic.ts:1224:33) at TouchCircuitCommands.setCircuitStateAsync (/home/pi/nodejs-poolController/controller/boards/EasyTouchBoard.ts:1535:31) at /home/pi/nodejs-poolController/web/services/state/State.ts:300:55 at Layer.handle [as handle_request] (/home/pi/nodejs-poolController/node_modules/express/lib/router/layer.js:95:5) at next (/home/pi/nodejs-poolController/node_modules/express/lib/router/route.js:144:13) at Route.dispatch (/home/pi/nodejs-poolController/node_modules/express/lib/router/route.js:114:3) at Layer.handle [as handle_request] (/home/pi/nodejs-poolController/node_modules/express/lib/router/layer.js:95:5) at /home/pi/nodejs-poolController/node_modules/express/lib/router/index.js:284:15 at Function.process_params (/home/pi/nodejs-poolController/node_modules/express/lib/router/index.js:346:12) at next (/home/pi/nodejs-poolController/node_modules/express/lib/router/index.js:280:10) at /home/pi/nodejs-poolController/web/Server.ts:749:25 at Layer.handle [as handle_request] (/home/pi/nodejs-poolController/node_modules/express/lib/router/layer.js:95:5) at trim_prefix (/home/pi/nodejs-poolController/node_modules/express/lib/router/index.js:328:13) at /home/pi/nodejs-poolController/node_modules/express/lib/router/index.js:286:9 at Function.process_params (/home/pi/nodejs-poolController/node_modules/express/lib/router/index.js:346:12) at next (/home/pi/nodejs-poolController/node_modules/express/lib/router/index.js:280:10)

rstrouse commented 1 year ago

Are you connecting with ScreenLogic?

arrmo commented 1 year ago

Nope,

1|njsPC  | [3/16/2023, 2:20:45 PM] info: Found IntelliTouch Controller
1|njsPC  | Pentair IntelliTouch System Detected!
rstrouse commented 1 year ago

I need your stack dump. The one above is clearly going into ScreenLogic. Double check to make sure you do not have a port set up for screenlogic in the comms section.

jwtaylor310 commented 1 year ago

I haven't done anything intentionally to enable ScreenLogic. Currently when I open the 'RS485' tab in the web interface it hangs with a yellow box that says "Getting Port Settings", so I can't get to the Comms section there. I have pulled the following from the config.json file:

{ "controller": { "comms": { "portId": 0, "enabled": true, "rs485Port": "/dev/ttyUSB0", "mock": false, "netConnect": true, "netHost": "xxx.xxx.xxx.xxx", <- actual IP hidden for security reasons "netPort": 8899, "inactivityRetry": 10, "portSettings": { "baudRate": 9600, "dataBits": 8, "parity": "none", "stopBits": 1, "rtscts": false, "autoOpen": false, "lock": false, "flowControl": false }, "netSettings": { "allowHalfOpen": false, "keepAlive": false, "keepAliveInitialDelay": 5 }, "screenlogic": { "connectionType": "local", "systemName": "Pentair: 00-00-00", "password": 1234 }, "type": "netConnect" },

How do I get a stack dump?

rstrouse commented 1 year ago

I was talking to @armo about the stack dump. You already provided yours but this is helpful.

arrmo commented 1 year ago

Need something from me? No issue at all, just let me know.

Thanks!

rstrouse commented 1 year ago

No worries we ended up with this issue and a discussion at the same time. I assume you are up and running at this point. Is that correct?

arrmo commented 1 year ago

Yep - just going in, re-saving settings ... fixed it. Didn't change a thing, just saved. Make sense?

rstrouse commented 1 year ago

Yes it does in your case. @jwtaylor310 shut down njsPC and manually change the line where it says "type": "netConnect", to "type": "network", then restart njsPC.

jwtaylor310 commented 1 year ago

I'm still having the problem. To confirm, I am supposed to make the "type" change in config.json, not defaultConfig.json? Here's what I currently have in config.json: { "controller": { "comms": { "type": "network", "portId": 0, "enabled": true, "rs485Port": "/dev/ttyUSB0", "mock": false, "netConnect": true, "netHost": "xxx.xxx.xxx.xxx", "netPort": 8899, "inactivityRetry": 10, "portSettings": { "baudRate": 9600, "dataBits": 8, "parity": "none", "stopBits": 1, "rtscts": false, "autoOpen": false, "lock": false, "flowControl": false }, "netSettings": { "allowHalfOpen": false, "keepAlive": false, "keepAliveInitialDelay": 5 }, "screenlogic": { "connectionType": "local", "systemName": "Pentair: 00-00-00", "password": 1234 } }, "backups": { "automatic": false, "interval": { "days": 30, "hours": 0 }, "keepCount": 5, "njsPC": true, "servers": [] } },

rstrouse commented 1 year ago

Ok now try to go into the COMMs again in dashPanel. You updated that software as well... correct?

rstrouse commented 1 year ago

Not defaultConfig.json. That is not a user file.

jwtaylor310 commented 1 year ago

No improvement. dashPanel still hangs at "Getting Port Settings..." So I can't see the Comms tab. Reloading the page clears the message and returns me to the main page. When I try to turn on/off a feature I still get error message "Cannot read properties of undefined (reading 'setCircuitStateAsync'). The stack trace is:

TypeError: Cannot read properties of undefined (reading 'setCircuitStateAsync') at SLCircuits.setCircuitStateAsync (/home/pi/nodejs-poolController/controller/comms/ScreenLogic.ts:1224:33) at TouchCircuitCommands.setCircuitStateAsync (/home/pi/nodejs-poolController/controller/boards/EasyTouchBoard.ts:1535:31) at /home/pi/nodejs-poolController/web/services/state/State.ts:300:55 at Layer.handle [as handle_request] (/home/pi/nodejs-poolController/node_modules/express/lib/router/layer.js:95:5) at next (/home/pi/nodejs-poolController/node_modules/express/lib/router/route.js:144:13) at Route.dispatch (/home/pi/nodejs-poolController/node_modules/express/lib/router/route.js:114:3) at Layer.handle [as handle_request] (/home/pi/nodejs-poolController/node_modules/express/lib/router/layer.js:95:5) at /home/pi/nodejs-poolController/node_modules/express/lib/router/index.js:284:15 at Function.process_params (/home/pi/nodejs-poolController/node_modules/express/lib/router/index.js:346:12) at next (/home/pi/nodejs-poolController/node_modules/express/lib/router/index.js:280:10) at /home/pi/nodejs-poolController/web/Server.ts:749:25 at Layer.handle [as handle_request] (/home/pi/nodejs-poolController/node_modules/express/lib/router/layer.js:95:5) at trim_prefix (/home/pi/nodejs-poolController/node_modules/express/lib/router/index.js:328:13) at /home/pi/nodejs-poolController/node_modules/express/lib/router/index.js:286:9 at Function.process_params (/home/pi/nodejs-poolController/node_modules/express/lib/router/index.js:346:12) at next (/home/pi/nodejs-poolController/node_modules/express/lib/router/index.js:280:10)

I have rebooted, confirmed the change to the config.json file and restarted both njsPC and the dashPanel. Both njrPC and dashPanel are at 8.0.0. njsPC is commit bedd29e. and dashPanel is commit cb05840.

rstrouse commented 1 year ago

Pull njsPC I added another check to disable ScreenLogic. I'll have to get @tagyoureit to have a look at this since it initializes it on startup even when there is no selected connection.

jwtaylor310 commented 1 year ago

That fixed the problem. After pulling the updated njsPC, I had to reset the "type" entry in config.json from "network" to "netConnect" to get comms working normally. Once I did that, the problem turning on/off features went away. In the meantime, I found that the problem with the dashPanel hanging at "Getting Port Settings..." was due to cached content in my browser. Now that I have cleared the cache, I can access the 'Comms" tab without a problem.

THANK YOU for working through this. Great support!

rstrouse commented 1 year ago

No worries. Turns out there were some default settings that needed to get sorted out.