Error on close, save, restart of node-red

I have a scenario where I have a bunch of custom nodes that I created that leverage a configuration node. I built the configuration node to run against the @elasticsearch/elasticsearch nodejs client lib. It has worked great on previous systems we have mostly running nodejs 12, node-red <2.0, etc.

Now I have just stood up a system which has nodejs 14, node-red 2 and I notice that every single time there is a flow that contains a node that references this particular config server, I can't save nodes.....it looks like on close something is happening where the same source code as before is throwing exceptions out of the @node-red/runtime/lib/nodes/Node.js file @ log_helper per below:

The Configuration Server is very basic in that it is simply creates a client from properties it collects from the form and adds to this per below, I don't have a node.on method in it but it seems that the close always happens across all my es nodes when they wire to the actual config node.

function ElasticsearchServerNode(n) {
    this.id = n.id;
    this.host = n.host;
    this.name = n.name;
    this.apikey = n.apikey;
    this.client = qs.api.getClient(this.url, this.apikey); 
}

RED.nodes.registerType("elasticsearch-node", ElasticsearchServerNode);

And this has worked without change for quite a while. Another thing I will mention is this doesn't happen when a configuration node is not in play....for all other nodes, etc it seems that it will save close/spin back up fine. Additionally the biggest way I see this occurring is when I click deploy, or Ctl+C out of node red running in the foreground... if I deploy then the node actually saves but I immediately get the following on the UI

Screen Shot 2021-07-27 at 9.55.59 AM

If I attempt to deploy again it asks for a Merge a few times, and then at one point seems to take it. However if I attempt to run the flow after this I get
Screen Shot 2021-07-27 at 9.57.13 AM

Any advice/assistance is greatly appreciated!
Justin

Just a follow up in case it helps someone else. I traced this to the node-red Node.js within runtime/lib dir and specifically what I saw with my use case was that the prototype definition for associating close with the Node object did not have null checks for properties (_closeCallbacks was not present on this object). My assumption is some versioning between the components is likely the disconnect but still.....

Once I started modifying the Node.js file and adding null checks to prevent undefined bails...it works fine now. Not sure if the implementation of this complicates other matters or masks another underlying issue somewhere but....

The issue is you config node constructor is missing the call to RED.nodes.createNode(this,config) as described in the docs here: JavaScript file : Node-RED

Without that call, your node isn't being properly initialised so is missing lots of key properties.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.