mikakaraila / node-red-contrib-opcua

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

Invalid Channel BadConnectionClosed #638

Open keyadelta opened 6 months ago

keyadelta commented 6 months ago

Hello, i've been working on monitoring system using this opc ua node. The case if whenever the machine turned off, the opc ua client will show the error "invalid Channel BadConnectionClosed". I've tried using an inject node with message "reconnect" with interval every morning at 6 am but the reconnect node made another error where the opc ua client won't close the session and renew it. Hereby i attached some of the logs when the error occurs and does anybody knows how to reconnect the correct way by taking the error message to reconnect by function inject?

8 Dec 13:41:29 - [error] [OpcUa-Client:a54bd6d9bd82477a] Client node error on: error: [" error at active reading: Invalid Channel BadConnectionClosed"] 8 Dec 13:41:29 - [error] [OpcUa-Client:a54bd6d9bd82477a] Client node error on: error: [" error at active reading: Invalid Channel BadConnectionClosed"] 8 Dec 13:41:29 - [error] [OpcUa-Client:a54bd6d9bd82477a] Client node error on: error: [" error at active reading: Invalid Channel BadConnectionClosed"] 8 Dec 13:41:29 - [error] [OpcUa-Client:a54bd6d9bd82477a] Client node error on: error: [" error at active reading: Invalid Channel BadConnectionClosed"] 06:41:39.806Z :client_session_keepalive_manag:159 warning : ClientSessionKeepAliveManager#ping_server Invalid Channel BadConnectionClosed

mikakaraila commented 6 months ago

Look #532 you could try to disconnect first.

keyadelta commented 6 months ago

Screenshot 2023-12-13 151549

I've tried using disconnect using manual inject, but i wanted it to automatically reconnect when a specific error occurs, so i used this function to inject "reconnect" when "Error: Invalid Channel BadConnectionClosed"

let errorOccurredBefore = context.get('errorOccurredBefore') || false; let error = msg.error; let status = msg.status; if (error === "Error: Invalid Channel BadConnectionClosed" && !errorOccurredBefore) { msg.topic = "Reconnect"; msg.action = "reconnect"; msg.opcUAEndpoint = { credentials: {}, endpoint: "opc.tcp://192.168.48.14:4840", securityPolicy: "None", securityMode: "None", login: false, }; context.set('errorOccurredBefore', true); } else { context.set('errorOccurredBefore', false); } return msg;

thus the function make another error with this log: 13 Dec 15:07:19 - [warn] [OpcUa-Client:opc] opc: can't work without OPC UA NodeId - msg.topic empty

mikakaraila commented 6 months ago

Another case can be that if you use two computers time difference is more than 60s. And use disconnect before you try to reconnect, just in case you have still connection objects on client side.

Pietro395 commented 6 months ago

Hello @mikakaraila I have the same problem, I've create a status node to monitor the "BadConnectionClosed" message, when this happens I connected an OPC client with the same endpoint with the DISCONNECT action but I have the same error as @keyadelta: DISCONNECT: can't work without OPC UA NodeId - msg.topic empty"

How should it work? how can I disconnect the client that is stuck with the error "BadConnectionClosed"?

Thank you

Pietro395 commented 6 months ago

Hello @mikakaraila I have the same problem, I've create a status node to monitor the "BadConnectionClosed" message, when this happens I connected an OPC client with the same endpoint with the DISCONNECT action but I have the same error as @keyadelta: DISCONNECT: can't work without OPC UA NodeId - msg.topic empty"

How should it work? how can I disconnect the client that is stuck with the error "BadConnectionClosed"?

Thank you

I think I solved it with reconnect and a function with this code. I will check the problem in the next few days

if (msg.status.text.includes('BadConnect')) {
    return {action: "reconnect", topic: "reconnect"}
}

immagine

keyadelta commented 6 months ago

Hello @mikakaraila I have the same problem, I've create a status node to monitor the "BadConnectionClosed" message, when this happens I connected an OPC client with the same endpoint with the DISCONNECT action but I have the same error as @keyadelta: DISCONNECT: can't work without OPC UA NodeId - msg.topic empty" How should it work? how can I disconnect the client that is stuck with the error "BadConnectionClosed"? Thank you

I think I solved it with reconnect and a function with this code. I will check the problem in the next few days

if (msg.status.text.includes('Badconnect')) {
    return {action: "reconnect", topic: "reconnect"}
}

immagine

is there any update by using this function code ? Does the OPC UA Client still stuck with the badconnectionclosed error?

Pietro395 commented 6 months ago

Hello @mikakaraila I have the same problem, I've create a status node to monitor the "BadConnectionClosed" message, when this happens I connected an OPC client with the same endpoint with the DISCONNECT action but I have the same error as @keyadelta: DISCONNECT: can't work without OPC UA NodeId - msg.topic empty" How should it work? how can I disconnect the client that is stuck with the error "BadConnectionClosed"? Thank you

I think I solved it with reconnect and a function with this code. I will check the problem in the next few days

if (msg.status.text.includes('BadConnect')) {
    return {action: "reconnect", topic: "reconnect"}
}

immagine

is there any update by using this function code ? Does the OPC UA Client still stuck with the badconnectionclosed error?

From our tests seems that this function resolve the problem

mikakaraila commented 6 months ago

Before making PR, I would like to test this with the latest node-opcua. There has been some updates... you could try to install v2.118.0 and test with it.

Pietro395 commented 6 months ago

Before making PR, I would like to test this with the latest node-opcua. There has been some updates... you could try to install v2.118.0 and test with it.

We have now installed the version, we are waiting to see if the problem occurs again and we will let you know

Pietro395 commented 5 months ago

Before making PR, I would like to test this with the latest node-opcua. There has been some updates... you could try to install v2.118.0 and test with it.

We've been using the latest version for a few weeks now, we haven't had the problem, but it could be that it was covered by the reconnect logic I was explaining in previous comments

eduardo-leite-oliveira commented 1 month ago

Hello @mikakaraila I have the same problem, I've create a status node to monitor the "BadConnectionClosed" message, when this happens I connected an OPC client with the same endpoint with the DISCONNECT action but I have the same error as @keyadelta: DISCONNECT: can't work without OPC UA NodeId - msg.topic empty" How should it work? how can I disconnect the client that is stuck with the error "BadConnectionClosed"? Thank you

I think I solved it with reconnect and a function with this code. I will check the problem in the next few days

if (msg.status.text.includes('BadConnect')) {
    return {action: "reconnect", topic: "reconnect"}
}

immagine

Hi Pietro!

I tried to create a function node like you but I received the error: cannot read properties of undefined (reading 'text')

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;

Do you know what is wrong?