BiancoRoyal / node-red-contrib-iiot-opcua

deprecated - very new developed by PLUS for Node-RED - https://plus4nodered.com
https://www.npmjs.com/package/node-red-contrib-iiot-opcua
BSD 3-Clause "New" or "Revised" License
34 stars 8 forks source link

Node-red crashes when quickly restart OPCUA server using Listening & Read node #127

Closed DenisJuan closed 2 years ago

DenisJuan commented 4 years ago

Dear sir,

Information

Current behaviour Connecting a read and a listen node to UAAnciCServer and restarting quickly the server, node red crashes with following error: _TypeError:` Cannot read property 'removeAllListeners' of null at C:\Users....node-red\node_modules\node-red-contrib-iiot-opcua\opcuaIIoT\maps\opcua-iiot-listener.js:660:46 at Immediate. (C:\Users....node-red\node_modules\node-opcua-client\src\clientsubscription.js:341:9) at processImmediate (internal/timers.js:439:21)

Expected behaviour No crash.

Minimal reproduction of the problem with instructions

  1. Import following nodes Nodes export: [{"id":"11041566.a2a3cb","type":"OPCUA-IIoT-Inject","z":"9769555a.aa4738","injectType":"listen","payloadType":"json","topic":"","repeat":"","crontab":"","once":true,"startDelay":"","name":"Config Listener","payload":"{\"interval\":200,\"queueSize\":1,\"options\":{\"requestedPublishingInterval\":200,\"requestedLifetimeCount\":60,\"requestedMaxKeepAliveCount\":10,\"maxNotificationsPerPublish\":5,\"publishingEnabled\":true,\"priority\":8}}","addressSpaceItems":[{"name":"Double","nodeId":"ns=4;s=Demo.Dynamic.Scalar.Double","datatypeName":"Double"},{"name":"Float","nodeId":"ns=4;s=Demo.Dynamic.Scalar.Float","datatypeName":"Float"},{"name":"Int16","nodeId":"ns=4;s=Demo.Dynamic.Scalar.Int16","datatypeName":"Int16"},{"name":"Int32","nodeId":"ns=4;s=Demo.Dynamic.Scalar.Int32","datatypeName":"Int32"},{"name":"Int64","nodeId":"ns=4;s=Demo.Dynamic.Scalar.Int64","datatypeName":"Int64"},{"name":"Byte","nodeId":"ns=4;s=Demo.Dynamic.Scalar.Byte","datatypeName":"Byte"}],"x":220,"y":440,"wires":[["e804c979.17e548"]]},{"id":"e804c979.17e548","type":"OPCUA-IIoT-Listener","z":"9769555a.aa4738","connector":"b3d7e00c.ec53f","action":"subscribe","queueSize":"1","name":"Grouped Listener","topic":"","justValue":true,"useGroupItems":true,"showStatusActivities":false,"showErrors":false,"x":510,"y":440,"wires":[["1325cdc6.b41452"]]},{"id":"1325cdc6.b41452","type":"debug","z":"9769555a.aa4738","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":710,"y":440,"wires":[]},{"id":"2dad4e3e.f04342","type":"OPCUA-IIoT-Read","z":"9769555a.aa4738","attributeId":"13","maxAge":1,"depth":1,"connector":"b3d7e00c.ec53f","name":"","justValue":true,"showStatusActivities":true,"showErrors":true,"parseStrings":false,"historyDays":1,"serverMaxItemsToRead":1000,"x":470,"y":520,"wires":[["b2ec41da.0cc9e"]]},{"id":"b8a84ae0.1e4f58","type":"OPCUA-IIoT-Inject","z":"9769555a.aa4738","injectType":"read","payloadType":"json","topic":"","repeat":"0.2","crontab":"","once":true,"startDelay":"","name":"Config Read","payload":"{\"interval\":200,\"queueSize\":1,\"options\":{\"requestedPublishingInterval\":200,\"requestedLifetimeCount\":60,\"requestedMaxKeepAliveCount\":10,\"maxNotificationsPerPublish\":5,\"publishingEnabled\":true,\"priority\":8}}","addressSpaceItems":[{"name":"Double","nodeId":"ns=4;s=Demo.Dynamic.Scalar.Double","datatypeName":"Double"},{"name":"Float","nodeId":"ns=4;s=Demo.Dynamic.Scalar.Float","datatypeName":"Float"},{"name":"Int16","nodeId":"ns=4;s=Demo.Dynamic.Scalar.Int16","datatypeName":"Int16"},{"name":"Int32","nodeId":"ns=4;s=Demo.Dynamic.Scalar.Int32","datatypeName":"Int32"},{"name":"Int64","nodeId":"ns=4;s=Demo.Dynamic.Scalar.Int64","datatypeName":"Int64"},{"name":"Byte","nodeId":"ns=4;s=Demo.Dynamic.Scalar.Byte","datatypeName":"Byte"}],"x":220,"y":520,"wires":[["2dad4e3e.f04342"]]},{"id":"b2ec41da.0cc9e","type":"debug","z":"9769555a.aa4738","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":620,"y":520,"wires":[]},{"id":"b3d7e00c.ec53f","type":"OPCUA-IIoT-Connector","z":"","discoveryUrl":"","endpoint":"opc.tcp://localhost:48020/","keepSessionAlive":true,"loginEnabled":false,"securityPolicy":"None","securityMode":"NONE","name":"UAAnsiCServer","showErrors":false,"individualCerts":false,"publicCertificateFile":"","privateKeyFile":"","defaultSecureTokenLifetime":"","endpointMustExist":false,"autoSelectRightEndpoint":false,"strategyMaxRetry":"","strategyInitialDelay":"","strategyMaxDelay":"","strategyRandomisationFactor":"","requestedSessionTimeout":"","connectionStartDelay":"","reconnectDelay":"","maxBadSessionRequests":"10"}]
  2. Install UAAnsiCServer (https://www.unified-automation.com/downloads/opc-ua-servers.html)
  3. Start UAAnsiCServer
  4. Start flow.
  5. When "Listen" node listen : "Listening(6)", Close UAAnsiCServer and restart it in less than 2 seconds.
  6. Node-red crashes.

Reproduction: 100%

Your Environment

Please tell us about your environment:

I'm using node-red with node-red-contrib-iiot-opcua (3.12.0) and node-opcua installed automaticall with it (0.7.4)

DenisJuan commented 4 years ago

In the "opcua-iiot-listener.js" file, I searched for every removeAllListeners occurences and add a NULL checking of parent (I'm novice in js / bianco syntax, so hope these following modifications are OK especially the third one). In my case, Node-red doesn't crash anymore.

I have checked "removeAllListeners" occurences in other js files and most of them are protected against NULL pointer.

Best regards,