st-one-io / node-red-contrib-s7

A Node-RED node to interact with Siemens S7 PLCs
GNU General Public License v3.0
108 stars 55 forks source link

ECONNRESET when PLC connection drops #91

Open matteoangrisano opened 3 years ago

matteoangrisano commented 3 years ago

Hello, I have a problem with Node-RED: continuously communicates with PLCs using node-red-contrib-s7, it worked well for a long time, once migrated Node.JS and Node-RED (without changes to the flows) from a machine with Windows 7 to a machine with Windows Server 2012 r2, I started getting the following error after a day or two:

16 Mar 10:33:01 - Error: read ECONNRESET at TCP.onStreamRead (node: internal / stream_base_commons: 211: 20)

this error stops Node-RED

Node.js version: 15.11.0 npm version: 7.6.1 Node-RED version: 1.2.9

I also tried with Node.js V14 but the error reoccurred.

I noticed that the problem occurs when the connection with a PLC is missing for more than a few minutes.

Last part of the logs:

7 Apr 11:30:39 - [error] [s7 endpoint:PLC - Pozzi Vasca Vecchia] Error: Timeout connecting to the transport 7 Apr 11:30:40 - [error] [s7 endpoint:PLC - Pozzi Vasca Nuova] Error: Timeout connecting to the transport 7 Apr 11:30:54 - [error] [s7 endpoint:PLC - Pozzi Vasca Vecchia] Error: Timeout connecting to the transport 7 Apr 11:30:55 - [error] [s7 endpoint:PLC - Pozzi Vasca Nuova] Error: Timeout connecting to the transport 7 Apr 11:31:10 - [error] [s7 endpoint:PLC - Pozzi Vasca Nuova] Error: Timeout connecting to the transport 7 Apr 11:31:13 - [red] Uncaught Exception: 7 Apr 11:31:13 - Error: read ECONNRESET at TCP.onStreamRead (internal/stream_base_commons.js:209:20)

gfcittolin commented 3 years ago

Have you updated the node-red-contrib-s7's version as well in the process, or just the environment has been updated? If yes, which was the previous and what is the current version?

matteoangrisano commented 3 years ago

Have you updated the node-red-contrib-s7's version as well in the process, or just the environment has been updated? If yes, which was the previous and what is the current version?

I probably also updated the version of node-red-contrib-s7, unfortunately I don't remember which one was the old one.

capIdxItaly commented 3 years ago

Same probelm with library "plcindustry v2.1.1" Node.js version: 14.15.4 npm version: 6.14.10 Node-RED version: 1.2.7

and with Node.js version: 14.16.0 npm version: 6.14.11 Node-RED version: 1.2.9

The problems show itself (for me) only on startup if a node is saved in memory. If i cancel the node from the flow file and after that I'll import the same node deletd earlier it stays on like it's supposed to be.

matteoangrisano commented 3 years ago

@gfcittolin any update for this issue?

dan-costello commented 2 years ago

@gfcittolin I am having this issue as well. s7-in node reports "ECONNRESET" after PLC drops connectivity and does not resume connectivity when PLC is reconnected. As capIdxItaly suggested, if i remove flow from file and reimport and deploy, the node works as designed. Do you have any updates?

dan-costello commented 2 years ago

@gfcittolin I found this update for the nodeS7 this project was built on. Could this update be implemented here? https://github.com/plcpeople/nodeS7/commit/4a0c964a8eeccea145190bda2c277e4c0a1c6317

matteoangrisano commented 2 years ago

@gfcittolin I found this update for the nodeS7 this project was built on. Could this update be implemented here? plcpeople/nodeS7@4a0c964

@gfcittolin is this possible?

gfcittolin commented 2 years ago

The fix of plcpeople's nodeS7 is not applicable here, since we don't use it anymore from version 3.0.0 onwards.

The problem with unhandled ECONNRESET on Node-RED is that it can come from any node that handles TCP connection, not necessarily this one. Had a problem with a customer last week regarding ECONNRESETs killing Node-RED, and the culprit was a modbus node, even though the connection to the PLC was unstable too.

Although I wouldn't rule it out that it comes from this node, I've checked the error handling paths and there's no obvious and not-so-obvious missing error handling. I couldn't also simulate the issue, although specific network conditions and timings could be critical for reproducing the issue.

Could you guys please confirm if the issue happens in a flow with a single s7 in node and nothing else?

RenaudHoule commented 2 years ago

Happens to me also, the s7 node is in a subflow and the plc address is an environment variable passed to the subflow, i have approx 10 flows using the same subflow (containing 1 node s7). It works great for a while, but at some point, it throws the same error as mentioned by OP.

I run node-red in a docker container, i tried with all the latest image from node-red using latest-12, latest-14 and i just started the container using latest-16 as i write this.

The only other node that communicates TCP is a mysql node to store the values retrieved from the plc into a database. But i doubt it is the mysql node that throws node-red off, because the error always happens after an error like this one:

10 Feb 07:52:18 - [error] [s7 endpoint:cf57728c984fdca8] Error: read ECONNRESET

Unfortunately, i restarted the docker containers so the logs disappeared but it's exactly as OP mentioned

I would like to help but i have no knowledge in writing nodes...... i can supply the flow JSON if necessary

Thanks

EDIT:

Also, I am using your s7 node in another project that's been running for a while without issue, but the node-red version is 1.2.9 and the s7 node version is 3.0.0.

EDIT2:

More precision, i have machine all over the world connected to a central vpn (which is used by nodered and s7 node to communicate to the plc) but it can be pretty frequent that a PLC is offline for an extended period of time. that is maybe why, at some point, the s7 node is "tired" of trying to connect to an offline PLC and crash.

EDIT 3:

It just crashed, here's the log:

11 Feb 11:26:54 - [red] Uncaught Exception: 11 Feb 11:26:54 - [error] Error: read ECONNRESET at TCP.onStreamRead (internal/stream_base_commons.js:209:20) npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! node-red-docker@2.2.0 start: node $NODE_OPTIONS node_modules/node-red/red.js $FLOWS "--userDir" "/data" npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the node-red-docker@2.2.0 start script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in: npm ERR! /data/.npm/_logs/2022-02-11T16_26_54_888Z-debug.log