Custom node status change causes CPU spike to %100

Hi,

I am using azure iot hub nodes (there is an official one and some alternative forks from that). The developer of that node wrote some node status updates based on connectivity to iot hub like connected, disconnected, sent, received etc.

Using that node i noticed my cpu is always up to %100, node red ui and backend was responsive though. Didn't feel comfortable using it that way.

After hours of debugging and many cups of flat whites i found out that, cpu spike is not present only when i disable status changing lines.

I would really appreciate if we can spot the root cause and fix this either in the node red core or if its a problem with the implementation, on the custom node side.

This is the node i am mentioning,

Best regards,

Hi Alper,
I dont know this node, but I assume the setStatus function is called very frequently??? You could add a simple counter in the code to get an idea of the frequency. And if it us called at high speed, you could also check whether it is sending the same status N times in a sequence, which has no use at all. Because I don't think the core of Node-RED filters out successive duplicate status update requests.
Bart

Nope, checked it.

One detail though, i think the problem is only happening when it tries to set a status on a callback function, something like :

let client = Client.fromConnectionString(deviceConnectionString, Protocol);
            client.open(function (err) {
            if (err) {
                 node.error('Could not connect: ' + err.message);
                 return
               } else {
                node.log('Connected');
                node.status({ fill: "green", shape: "dot", text: "Connected" }); // this is making cpu go 100%
               }

Are you sure it is not some other effect caused by the fact that is connected? If you remove the node.status line but leave everything else as it is does it sort the problem. If it does sort it then have you got a status node picking that up and doing something with it? If so then then put the node.status line back but disconnect the output of the status node so it does nothing.

Seems its all normal, i had a node status capture node but it is only being triggered rarely. It is only caused by status change lines and only if they are in the azure connection callbacks

What's all normal?

node status change is only being called in reasonable times like lets says 3 times in 5 minutes. And in the node status capturing, code only runs only once for each status change, meaning 3 times.

It would still be useful to feed this back to the author of the node. I can't immediately see why this should cause what you see - but at least make them aware.
(Also to be consistent the err path should also set an error status - but of course that may make things worse :slight_smile:

If you disconnect the output of the status node are you still seeing the spikes?

Yes i am still seeing the spike even if i disconnect or delete status nodes. well this have caused a good thing and i have written my own custom node based on azure iot hub node.js sdk and seems i can use statuses as well without any problems. Gave up trying to find why the azure provided node was not working as expected.