Hi,
I have created simple custom nodes to send messages in Node RED. I'm facing issue when I modify the flow and deploy it. Changes wont get reflected first time. If I delete the changes and make same changes again, then it works. For example if I have a flow with nodes x, y , z with x -> y -> z and if I add a->y , this change doesn't get reflected first time. But if I delete node a and again add it second time, then it works. I'm not sure why this is happening.
I'm using Node-RED v3.0.2 and node.js v16.20.1. I'm building Node RED from source.
Any help on fixing this issue will be greatly appreciated.
If you try it on a normal install of node red do you see the same problem?
I will try this normal install and check.
What do you mean by 'does not get reflected`? What exact symptom are you seeing?
When I make new connection a->y to the existing working flow x->y->z and deploy this new flow, the messages from node a are not sent to node y and the logs I have added in node a are not printed. But the flow x->y->z works fine. If I delete node a and reconnect it again to y second time, then message from node a is sent to node y and logs in node a are printed.
Also what are these nodes a,x,y,z? Are they all custom nodes that you have created?
yes, a, x, y, z are the custom nodes I have created which has simple functionality to send a message.
Is this related to your previous post in which you are trying to send a message when a new connection is made rather than under more normal circumstances? If so then I suggest continuing this on the original thread as it appears that the technique used to achieve that is not functioning as expected.
Under what circumstance does your node send messages? Is it when it receives a message? If it is then add logging into that code to see where it is failing.
Deploy the updated flow to see below output
Expected output -
{key : "dummy"}
{key : "dummy"}
Produced output :
{key : "dummy"}
Delete the extra nodes you added Step 7 and deploy the flow. Add the extra nodes back again as in Step 7 and deploy. Now it produces output as expected.
Please let me know if you are able to reproduce the issue or if you have need any clarifications.
Note : The issue doesn't occur always but it occurs frequently
Under what circumstance does your node send messages? Is it when it receives a message? If it is then add logging into that code to see where it is failing.
I have created two nodes namely, send-node and custom-node. send-node sends message when it is deployed. custom-node forwards message when it receives input message
probably a race condition because you are attempting to send before the node is fully created (i.e. before the current block is finished) and, more importantly, before Node-RED has emitted its update events.
As a test, put the node.send call in a setImmediate, nextTick or setTimeout
e.g.
msg._info = 'inside node creation, before it is fully registered'
node.send(msg);
setTimeout(() => {
msg._info = 'setTimeout'
node.send(msg);
}, 1); // 1 ms
setImmediate(() => {
msg._info = 'setImmediate'
node.send(msg);
});
process.nextTick(() => {
msg._info = 'nextTick'
node.send(msg);
})
and check the msg using a debug (set to show full msg object)