mikakaraila / node-red-contrib-opcua

A Node-RED node to communicate OPC UA. Uses node-opcua library.
Other
216 stars 197 forks source link

Handle errors in subscriptions & gracefully close sessions #661

Closed kurago-dev closed 9 months ago

kurago-dev commented 9 months ago

In this PR, two enhancements are introduced.

Subscription error handling (commit 2b75755...)

If the subscription limit of the OPC-UA was reached, an uncaught error would be raised, stopping Node-RED completely. Then, Node-RED would fail to start again (if set to restart on errors), since the amount of subscriptions is likely the same. Now, whenever there's an error on the subscription, it will be reported but Node-RED will continue working. Example of the new handling working:

TooManySubscriptions example

Gracefully close sessions (commit 809f458...)

When Node-RED was stopped, the node.on("close") handler wasn't waiting for all the flows to finish their tasks before closing Node-RED. If more than one flow had active OPC-UA sessions, some of them could be left open on the server. Now, the session.close() is awaited and the done() function is called in the end of the node.on("close") handler.

mikakaraila commented 9 months ago

Thanks, good one!