Restart flow on disconnected modbus on a truenas machine

I just redeploy the flow.
Sometimes, the problem is the node-red service itself (but very very rare) and I have to restart the service on the NAS.
But most of the error is the modbus disconnection (it's a modbus tcp/ip PLC). Restart flows and I'm on the road again.

Since 2 days, I just (blindly) added a set of functions harvested from here
(Restart flows using Node Red API) and it seems to work. I'll dig more about this but was in a hurry to implement this to avoid losing some data.

But I don't like this kind of "black box" solution. Stay tuned, if my modbus unit is disconnected again (and some data lost), I'll know and will search for other way to solve my problem.
But feel free to give me some theorical/practical clues.

modbus error restart