Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crash during error handling #2228

Closed
3 of 5 tasks
nospam2000 opened this issue Jul 10, 2019 · 3 comments
Closed
3 of 5 tasks

crash during error handling #2228

nospam2000 opened this issue Jul 10, 2019 · 3 comments

Comments

@nospam2000
Copy link

nospam2000 commented Jul 10, 2019

What are the steps to reproduce?

Use the following nodes :

  • "OPC UA Subscribe" from node-red-contrib-opcua, configured to connect to an unreachable server, so it emits an error
  • "catch" with "catch all"

Instead of "OPC UA Subscribe" any node can be used which calls node.error() with a string for the parameter msg:

    function node_error(err) {
      node.error(err, err);
    }

What happens?

node-red crashes with the following call-stack:

Welcome to Node-RED
===================

10 Jul 13:31:06 - [info] Node-RED version: v0.20.3
10 Jul 13:31:06 - [info] Node.js  version: v8.15.1
10 Jul 13:31:06 - [info] Linux 4.14.87-rt49+ x64 LE
10 Jul 13:31:07 - [info] Loading palette nodes
10 Jul 13:31:07 - [warn] rpi-gpio : Raspberry Pi specific node set inactive
10 Jul 13:31:07 - [warn] rpi-gpio : Cannot find Pi RPi.GPIO python library
Setting-up gobal tunnel with environment http_proxy.
10 Jul 13:31:11 - [info] Dashboard version 2.14.0 started at /ui
10 Jul 13:31:11 - [info] Settings file  : /home/nodered/sim-edge-settings.js
10 Jul 13:31:11 - [info] Context store  : 'default' [module=memory]
10 Jul 13:31:11 - [info] User directory : /home/nodered/node-red-home/
10 Jul 13:31:11 - [warn] Projects disabled : set editorTheme.projects.enabled=true to enable
10 Jul 13:31:11 - [info] Flows file     : /home/nodered/node-red-home/flows.json
10 Jul 13:31:12 - [info] Server now running at http://127.0.0.1:1880/
10 Jul 13:31:12 - [info] Starting flows
10 Jul 13:31:12 - [info] Started flows
10 Jul 13:31:12 - [error] [MySQLdatabase:3fd5768d.e2cf8a] Error: ER_DBACCESS_DENIED_ERROR: Access denied for user 'admin'@'%' to database 'SimEdge'
10 Jul 13:31:22 - [info] [mqtt-broker:7b9d47b7.e660b] Connection failed to broker: mqtt://mosquitto:1883
10 Jul 13:31:32 - [error] [MySQLdatabase:3fd5768d.e2cf8a] Error: ER_DBACCESS_DENIED_ERROR: Access denied for user 'admin'@'%' to database 'SimEdge'
10 Jul 13:31:47 - [info] [mqtt-broker:7b9d47b7.e660b] Connection failed to broker: mqtt://mosquitto:1883
10 Jul 13:31:52 - [error] [MySQLdatabase:3fd5768d.e2cf8a] Error: ER_DBACCESS_DENIED_ERROR: Access denied for user 'admin'@'%' to database 'SimEdge'
10 Jul 13:32:12 - [info] [mqtt-broker:7b9d47b7.e660b] Connection failed to broker: mqtt://mosquitto:1883
10 Jul 13:32:12 - [error] [mysql:a44078a1.02781] Database not connected
10 Jul 13:32:12 - [error] [MySQLdatabase:3fd5768d.e2cf8a] Error: ER_DBACCESS_DENIED_ERROR: Access denied for user 'admin'@'%' to database 'SimEdge'
10 Jul 13:32:32 - [error] [MySQLdatabase:3fd5768d.e2cf8a] Error: ER_DBACCESS_DENIED_ERROR: Access denied for user 'admin'@'%' to database 'SimEdge'
10 Jul 13:32:37 - [info] [mqtt-broker:7b9d47b7.e660b] Connection failed to broker: mqtt://mosquitto:1883
10 Jul 13:32:52 - [error] [MySQLdatabase:3fd5768d.e2cf8a] Error: ER_DBACCESS_DENIED_ERROR: Access denied for user 'admin'@'%' to database 'SimEdge'
10 Jul 13:33:02 - [info] [mqtt-broker:7b9d47b7.e660b] Connection failed to broker: mqtt://mosquitto:1883
10 Jul 13:33:12 - [error] [mysql:a44078a1.02781] Database not connected
10 Jul 13:33:12 - [error] [MySQLdatabase:3fd5768d.e2cf8a] Error: ER_DBACCESS_DENIED_ERROR: Access denied for user 'admin'@'%' to database 'SimEdge'
10 Jul 13:33:27 - [info] [mqtt-broker:7b9d47b7.e660b] Connection failed to broker: mqtt://mosquitto:1883
10 Jul 13:33:32 - [error] [MySQLdatabase:3fd5768d.e2cf8a] Error: ER_DBACCESS_DENIED_ERROR: Access denied for user 'admin'@'%' to database 'SimEdge'
10 Jul 13:33:39 - [info] Stopping flows
10 Jul 13:33:39 - [info] Stopped flows
10 Jul 13:33:39 - [info] Starting flows
10 Jul 13:33:39 - [info] Started flows
10 Jul 13:33:39 - [red] Uncaught Exception:
10 Jul 13:33:39 - TypeError: Cannot create property 'error' on string 'OPC UA Subscribe OPC UA connection error: connect EHOSTUNREACH 10.11.12.13:4840'
    at /home/nodered/node-red/packages/node_modules/@node-red/runtime/lib/nodes/flows/Flow.js:486:36
    at Array.forEach (<anonymous>)
    at Flow.handleError (/home/nodered/node-red/packages/node_modules/@node-red/runtime/lib/nodes/flows/Flow.js:465:29)
    at OpcUaClientNode.Node.error (/home/nodered/node-red/packages/node_modules/@node-red/runtime/lib/nodes/Node.js:276:30)
    at node_error (/home/nodered/node-red/node-red-contrib-opcua/opcua/102-opcuaclient.js:109:12)
    at /home/nodered/node-red/node-red-contrib-opcua/opcua/102-opcuaclient.js:316:13
    at /home/nodered/node-red/node-red-contrib-opcua/node_modules/async/dist/async.js:3888:9
    at /home/nodered/node-red/node-red-contrib-opcua/node_modules/async/dist/async.js:473:16
    at iterateeCallback (/home/nodered/node-red/node-red-contrib-opcua/node_modules/async/dist/async.js:988:17)
    at /home/nodered/node-red/node-red-contrib-opcua/node_modules/async/dist/async.js:969:16
    at /home/nodered/node-red/node-red-contrib-opcua/node_modules/async/dist/async.js:3885:13
    at Timeout.delayer [as _onTimeout] (/home/nodered/node-red/node_modules/delayed/delayed.js:27:10)
    at ontimeout (timers.js:498:11)
    at tryOnTimeout (timers.js:323:5)
    at Timer.listOnTimeout (timers.js:290:5)

What do you expect to happen?

An error should be sent as message to the "catch" node, because the OPC UA connection cannot be established.

Part of the problem lies in the function handleError() from packages/node_modules/@node-red/runtime/lib/nodes/flows/Flow.js which expects, that 'msg' is of type object, but in this case it is a string and therefore the last line causes the crash :

                var errorMessage;
                if (msg) {
                    errorMessage = redUtil.cloneMessage(msg);
                } else {
                    errorMessage = {};
                }
                if (errorMessage.hasOwnProperty("error")) {
                    errorMessage._error = errorMessage.error;
                }
                errorMessage.error = {

I would either just ignore msg if it is not of type object:

                var errorMessage;
                if (typeof(msg) == 'object') {
                    errorMessage = redUtil.cloneMessage(msg);
                } else {
                    errorMessage = {};
                }
                if (errorMessage.hasOwnProperty("error")) {
                    errorMessage._error = errorMessage.error;
                }
                errorMessage.error = {

or check if 'msg' is of type string and then create errorMessage as an object instead of using redUtil.cloneMessage(msg), but even then an 'else' for all other datatypes should be used.

I know that this is "just" a robustness issue, because 'msg' should not be of type string, but the fix is easy and the OPC UA Node is probably not the only one which does it wrong.

Please tell us about your environment:

  • Node-RED version: v0.20.3
  • node.js version: v8.15.1
  • npm version:
  • Platform/OS: Linux 4.14.87-rt49+ x64 LE
  • Browser:
@knolleary
Copy link
Member

The second argument of node.error() must be a message object. We can certainly add some error handling here, but to be clear, the node is not using the API correctly and an issue should be raised against it.

@nospam2000
Copy link
Author

I know, that's the next issue I will create

@knolleary
Copy link
Member

Have pushed a fix to dev (for the 1.0 release) that checks the 2nd arg is an Object before we try to handle it.

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

No branches or pull requests

2 participants