# OPC UA Client node error connection break

**URL:** <https://discourse.nodered.org/t/opc-ua-client-node-error-connection-break/88192>\
**Category:** General\
**Created:** [23 May 2024 10:33 UTC](https://discourse.nodered.org/t/opc-ua-client-node-error-connection-break/88192 "2024-05-23T10:33:28Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![Elo](https://avatars.discourse-cdn.com/v4/letter/e/e19b73/32.png) [@Elo](https://discourse.nodered.org/u/Elo)\
**Post date:** [23 May 2024 10:33 UTC](https://discourse.nodered.org/t/opc-ua-client-node-error-connection-break/88192/1 "2024-05-23T10:33:28Z")

</div>

I am trying to run node-red continuously to connect with the OpcUa server automatically when the injection machine turns on but I got the error below..

node-red version v3.1.9 and node.js version v18.20.2

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/7/1770034a32d3220fdeeb4950454701ee678cca4d.png)

22 May 18:44:30 - [error] [OpcUa-Client:b95eecf0ea19f418] Client node error on: error: [" error at active reading: Connection Break"]  
22 May 18:44:31 - [error] [OpcUa-Client:b95eecf0ea19f418] Client node error on: error: [" error at active reading: Invalid Channel BadConnectionClosed"]

\<--- Last few GCs ---\>

[14796:000002A718B7FA30] 29651103 ms: Scavenge 4031.9 (4125.5) -\> 4020.5 (4126.0) MB, 6.18 / 0.00 ms (average mu = 0.800, current mu = 0.171) task;  
[14796:000002A718B7FA30] 29653567 ms: Scavenge 4033.0 (4126.0) -\> 4021.2 (4126.7) MB, 6.24 / 0.00 ms (average mu = 0.800, current mu = 0.171) task;  
[14796:000002A718B7FA30] 29662571 ms: Mark-Compact 4146.5 (4240.1) -\> 4057.7 (4163.8) MB, 6578.87 / 0.00 ms (average mu = 0.719, current mu = 0.617) task; scavenge might not succeed

\<--- JS stacktrace ---\>

FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory  
----- Native stack trace -----

1: 00007FF6F330663B node::SetCppgcReference+18123  
2: 00007FF6F32783E4 v8::base::CPU::num\_virtual\_address\_bits+89412  
3: 00007FF6F3CEFA81 v8::Isolate::ReportExternalAllocationLimitReached+65  
4: 00007FF6F3CD91D8 v8::Function::Experimental\_IsNopFunction+1336  
5: 00007FF6F3B3AC20 v8::Platform::SystemClockTimeMillis+659328  
6: 00007FF6F3B37CA8 v8::Platform::SystemClockTimeMillis+647176  
7: 00007FF6F3AF38A8 v8::Platform::SystemClockTimeMillis+367624  
8: 00007FF6F32000B3 ENGINE\_get\_load\_privkey\_function+4803  
9: 00007FF6F31FEA66 node::TriggerNodeReport+82086  
10: 00007FF6F336C09B uv\_update\_time+491  
11: 00007FF6F336BC14 uv\_run+900  
12: 00007FF6F333CB15 node::SpinEventLoop+405  
13: 00007FF6F3224982 ENGINE\_get\_load\_privkey\_function+154514  
14: 00007FF6F32BCD6D node::Start+4909  
15: 00007FF6F32BBA70 node::Start+48  
16: 00007FF6F307D96C AES\_cbc\_encrypt+151452  
17: 00007FF6F44FF1BC inflateValidate+17308  
18: 00007FFE727A7344 BaseThreadInitThunk+20  
19: 00007FFE731E26B1 RtlUserThreadStart+33

---

<div class="post-metadata">

**Author:** ![GogoVega](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gogovega/32/71313_2.png) [@GogoVega](https://discourse.nodered.org/u/GogoVega)\
**Post date:** [23 May 2024 10:43 UTC](https://discourse.nodered.org/t/opc-ua-client-node-error-connection-break/88192/2 "2024-05-23T10:43:32Z")

</div>

> [@Elo](#):
>
> FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory

Seems related to [#4678](https://github.com/node-red/node-red/issues/4678).

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [23 May 2024 11:11 UTC](https://discourse.nodered.org/t/opc-ua-client-node-error-connection-break/88192/3 "2024-05-23T11:11:37Z")

</div>

> [@Elo](#):
>
> connect with the OpcUa server automatically when the injection machine turns on but I got the error below

Does the error occur when you turn it on or when you turn it off?

Does it work if the machine is already on when you start node-red?

Change the inject node to only fire when you click the button. Does it fail if you don't click it? Does it fail if you then click it?

---

<div class="post-metadata">

**Author:** ![Elo](https://avatars.discourse-cdn.com/v4/letter/e/e19b73/32.png) [@Elo](https://discourse.nodered.org/u/Elo)\
**Post date:** [23 May 2024 13:11 UTC](https://discourse.nodered.org/t/opc-ua-client-node-error-connection-break/88192/5 "2024-05-23T13:11:17Z")

</div>

> [@Colin](#):
>
> Does the error occur when you turn it on or when you turn it off?
> 
> Does it work if the machine is already on when you start node-red?
> 
> Change the inject node to only fire when you click the button. Does it fail if you don't click it? Does it fail if you then click it?

When I start node-red to run constinuosly I intend to connect automatically to the machine when it turns on.

The error occur when the machine stop the production for a long time or turn off.

When the machine is already on and I start node-red it's work.

If the inject node only fire when click it works if the machine is on.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [23 May 2024 13:41 UTC](https://discourse.nodered.org/t/opc-ua-client-node-error-connection-break/88192/6 "2024-05-23T13:41:49Z")

</div>

If you disconnect the wire out of the client node and just connect it to debug node instead, does it still fail when the machine turns off?

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [23 May 2024 13:46 UTC](https://discourse.nodered.org/t/opc-ua-client-node-error-connection-break/88192/7 "2024-05-23T13:46:07Z")

</div>

> [@Elo](#):
>
> If the inject node only fire when click it works if the machine is on.

You have not said what happens when the machine turns off. Does it immediately crash or not until you click the inject?

---

<div class="post-metadata">

**Author:** ![Elo](https://avatars.discourse-cdn.com/v4/letter/e/e19b73/32.png) [@Elo](https://discourse.nodered.org/u/Elo)\
**Post date:** [23 May 2024 14:03 UTC](https://discourse.nodered.org/t/opc-ua-client-node-error-connection-break/88192/8 "2024-05-23T14:03:11Z")

</div>

> [@Colin](#):
>
> If you disconnect the wire out of the client node and just connect it to debug node instead, does it still fail when the machine turns off?

Yes, the fail is related with the opc ua server and client connection, after client node isn't important.

---

<div class="post-metadata">

**Author:** ![Elo](https://avatars.discourse-cdn.com/v4/letter/e/e19b73/32.png) [@Elo](https://discourse.nodered.org/u/Elo)\
**Post date:** [23 May 2024 14:04 UTC](https://discourse.nodered.org/t/opc-ua-client-node-error-connection-break/88192/9 "2024-05-23T14:04:35Z")

</div>

> [@Colin](#):
>
> You have not said what happens when the machine turns off. Does it immediately crash or not until you click the inject?

When machine turns off it will try to reconnect every 30 sec till crash

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [23 May 2024 14:16 UTC](https://discourse.nodered.org/t/opc-ua-client-node-error-connection-break/88192/10 "2024-05-23T14:16:47Z")

</div>

> [@Elo](#):
>
> Yes, the fail is related with the opc ua server and client connection, after client node isn't important.

Are you certain about that?

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [23 May 2024 14:22 UTC](https://discourse.nodered.org/t/opc-ua-client-node-error-connection-break/88192/11 "2024-05-23T14:22:02Z")

</div>

If you are certain then I think you will have to submit an issue on the node's github page.

---

<div class="post-metadata">

**Author:** ![Elo](https://avatars.discourse-cdn.com/v4/letter/e/e19b73/32.png) [@Elo](https://discourse.nodered.org/u/Elo)\
**Post date:** [23 May 2024 14:57 UTC](https://discourse.nodered.org/t/opc-ua-client-node-error-connection-break/88192/12 "2024-05-23T14:57:11Z")

</div>

Yes, certainly. Thanks!

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [23 May 2024 16:18 UTC](https://discourse.nodered.org/t/opc-ua-client-node-error-connection-break/88192/13 "2024-05-23T16:18:24Z")

</div>

> [@Elo](#):
>
> When machine turns off it will try to reconnect every 30 sec till crash

How long is that?

And what frequency is the inject node running? Every 100ms? Every 1s?

I have a theory you are causing this issue.

Consider this, the inject runs every 100ms, and calls 15 network type nodes. All 15 nodes attempt to do a network request to the OPCUA server. They get eventually timeout, but all the while you keep inputting `msg`s into them, 15 more, 15 more, 15 more until 💥

It is just a theory but there may be something in it.

You might want to see if there is some way of determining the connection status (usually a status node pointed at the OPC UA Client node can work) - then add a switch after the inject to inhibit messages if the connection is offline & avoid filling the memory with queued requests.

---

<div class="post-metadata">

**Author:** ![Elo](https://avatars.discourse-cdn.com/v4/letter/e/e19b73/32.png) [@Elo](https://discourse.nodered.org/u/Elo)\
**Post date:** [23 May 2024 17:18 UTC](https://discourse.nodered.org/t/opc-ua-client-node-error-connection-break/88192/14 "2024-05-23T17:18:34Z")

</div>

> [@Steve-Mcl](#):
>
> How long is that?
> 
> And what frequency is the inject node running? Every 100ms? Every 1s?
> 
> I have a theory you are causing this issue.
> 
> Consider this, the inject runs every 100ms, and calls 15 network type nodes. All 15 nodes attempt to do a network request to the OPCUA server. They get eventually timeout, but all the while you keep inputting `msg`s into them, 15 more, 15 more, 15 more until 💥
> 
> It is just a theory but there may be something in it.
> 
> You might want to see if there is some way of determining the connection status (usually a status node pointed at the OPC UA Client node can work) - then add a switch after the inject to inhibit messages if the connection is offline & avoid filling the memory with queued requests.

I don´t know how long precisely, I'll try to check.

The frequency is every 50ms.

I´m trying to develop a way to handle the connection status but I received the error: cannot read properties of undefined (reading 'text')

```auto
let errorOccurredBefore = context.get('errorOccurredBefore') || false;
let error = msg.error;
let status = msg.status;
let text = msg.status.text;
if (error === "Error: Invalid Channel BadConnectionClosed" && !errorOccurredBefore) {
msg.topic = "Reconnect";
msg.action = "reconnect";
msg.opcUAEndpoint = {
credentials: {},
endpoint: "opc.tcp:xxxxxxx",
securityPolicy: "None",
securityMode: "None",
login: true,
user: "user",
password: "password"
};
context.set('errorOccurredBefore', true);
} else {
context.set('errorOccurredBefore', false);
}
if (msg.status.text.includes('BadConnect' || 'Connection Break')) {
return { action: "reconnect", topic: "reconnect" }
}
return msg;

```

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [23 May 2024 17:27 UTC](https://discourse.nodered.org/t/opc-ua-client-node-error-connection-break/88192/15 "2024-05-23T17:27:53Z")

</div>

> [@Elo](#):
>
> I received the error: cannot read properties of undefined (reading 'text')

did you set the status node to ONLY point at the singe client node?

To figure things out, you can use `node.warn({ stuff you want to inspect })` inside the function at key points.

---

<div class="post-metadata">

**Author:** ![Elo](https://avatars.discourse-cdn.com/v4/letter/e/e19b73/32.png) [@Elo](https://discourse.nodered.org/u/Elo)\
**Post date:** [24 May 2024 08:58 UTC](https://discourse.nodered.org/t/opc-ua-client-node-error-connection-break/88192/16 "2024-05-24T08:58:09Z")

</div>

> [@Steve-Mcl](#):
>
> did you set the status node to ONLY point at the singe client node?
> 
> To figure things out, you can use `node.warn({ stuff you want to inspect })` inside the function at key points.

Yes, I set to only point at client node. Thank you Steve-Mcl

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [22 August 2024 08:58 UTC](https://discourse.nodered.org/t/opc-ua-client-node-error-connection-break/88192/17 "2024-08-22T08:58:35Z")

</div>

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