IMD SolutionComputing LibraryShop main store

Troubleshooting

Why an uncaught ECONNRESET stops Node-RED when a PLC drops

Edge computing and IIoT Published 8 min read By IMD Solution engineering team

Short answer

Node-RED stops because the TCP reset reaches it as an uncaught exception: the S7 node or its transport dependency never caught the reset and left the connection state undefined, so the only safe runtime response is to exit. The fix belongs in that node or dependency, and neither Catch nodes nor runtime settings can intercept it. Verify by holding the PLC offline past your observed failure interval, restoring it, and requiring zero Uncaught Exception lines with the endpoint reconnected.

On this page
  1. Why does Node-RED exit instead of logging the reset and carrying on?
  2. Why does the crash appear minutes after the PLC went offline?
  3. Which component owns the fix for the uncaught exception?
  4. What can you change in your flow while the fix is pending?
  5. How do you reproduce the crash on demand?
  6. How do you verify a fix keeps Node-RED running?
  7. Could the network, not the node, be the real cause?
  8. Questions asked

Node-RED stops because a TCP reset reaches the runtime as an uncaught exception, not because the connection to the PLC dropped. In the reported failure a flow polls two PLCs through node-red-contrib-s7; after the connection has been missing for a few minutes the endpoints log repeated transport timeouts, the runtime prints an Uncaught Exception header with read ECONNRESET, and the process exits. The runtime is behaving as designed: it cannot know what state a node holds after an exception escapes that node's own handling. The fix belongs in the S7 node or the transport dependency beneath it, no Node-RED setting prevents the crash, and you verify a fix with a timed disconnect-and-restore test sized to your own logged failure interval.

Why does Node-RED exit instead of logging the reset and carrying on? #

Node-RED exits on purpose: once an exception escapes a node's own error handling, the runtime cannot know what internal state that node still holds, so stopping the process is the only response that avoids running the flow against a connection nobody cleaned up. A half-torn-down socket with stale buffers can replay old data or write to a session the PLC has already closed, and no runtime code can tell which of those states a given node is in.

The Node-RED project's position on this is explicit: a node must catch and handle its own exceptions, and only faults that make the runtime itself unable to continue, such as memory exhaustion, should reach the top level. An exit after an uncaught exception is the documented consequence, not a bug in your install or your flow. That is why upgrading Node-RED will not change the outcome: the exit is the safety behavior, and the missing handler is in the node.

Why does the crash appear minutes after the PLC went offline? #

Two different faults sit in that log: the repeated Timeout connecting to the transport lines are handled errors the S7 endpoint reports while the PLC is unreachable, while the fatal event is a read ECONNRESET that arrives on a live socket and is caught by nobody.

The sequence in the reported case makes the split visible. Both S7 endpoints log Error: Timeout connecting to the transport again and again while the connection is down; those lines are endpoint-level reporting and are not fatal. The terminating event comes later, on a socket that did get established:

[error] [s7 endpoint:PLC endpoint] Error: Timeout connecting to the transport
[red] Uncaught Exception:
Error: read ECONNRESET
    at TCP.onStreamRead (internal/stream_base_commons.js:209:20)

ECONNRESET means the TCP peer or something between the two hosts sent a reset on that established connection. The minutes-long delay before it appears is ordinary: while the PLC is simply unreachable, connect attempts time out, which the node handles; the fatal reset lands on a socket that opened and then died underneath the node, and that is the path the node never guarded.

Which component owns the fix for the uncaught exception? #

The S7 node or the transport dependency underneath it owns the fix: it must catch the TCP reset, discard the dead socket, and return the endpoint to a defined disconnected state before its reconnect logic runs, because only its author knows what internal state to rebuild.

Read the log as three signatures, each with its own owner:

  • Error: Timeout connecting to the transport from the s7 endpoint: a handled error, reported at endpoint level, not the cause of the exit.
  • read ECONNRESET at TCP.onStreamRead: the reset on an established socket that the node or its transport dependency failed to catch. The network caused it; the node failed to contain it.
  • [red] Uncaught Exception: immediately followed by the process stopping: the runtime's marker that the exception escaped node handling. Nothing in your flow or configuration produced this line.

The evidence pins the defect to the node's exception handling; it does not name the exact module, version, or code path, and neither the log nor the reported case identifies a corrected package version. Treat any claim that a given version fixed it as unverified until you run the test in the last section below on your own target.

What can you change in your flow while the fix is pending? #

No Node-RED setting prevents this crash: a Catch node only receives errors that nodes emit as messages, and the reset never becomes one, so the practical moves are a maintainer report with the full log, a fork that adds the handler, and a service manager that restarts the host.

The Catch node and the retry patterns built on it act on errors nodes deliver through the flow, so they are the right tool for handled endpoint errors and the wrong tool here. An exception that reaches the runtime has already left the node; no flow-side wiring can intercept it.

Report the reproducible sequence to the node maintainer with the complete log, from the first transport timeout through the Uncaught Exception line, so the fix targets the reset path and not just the timeouts. If the maintainer does not answer, fork the node and add the handler yourself: wrap the transport connect calls and socket data and error callbacks, and on a caught reset destroy the socket, mark the endpoint disconnected, and let the node's own reconnect logic run. Do not install a global handler that swallows uncaught exceptions without that cleanup; the node would keep running against a dead socket in undefined state, which is the exact condition the runtime exits to prevent.

While the handler work is under way, a service manager turns a hard stop into a short outage: the restart configuration for a Node-RED host that exits repeatedly is set up in Node-RED crash and memory growth: systemd restart recovery, and the same offline-buffering reasoning applies to the data your flow would otherwise drop at the moment of exit. That is a damper, not a fix; the endpoint still needs its own handler.

How do you reproduce the crash on demand? #

Take the PLC offline and hold it there well past the interval that previously produced the crash: expect the endpoint timeout lines to repeat, then the Uncaught Exception header and read ECONNRESET on TCP.onStreamRead, and nothing after that but the process exit.

The procedure:

  1. Record the interval from your own log: the time the connection went away to the time the Uncaught Exception line appeared.
  2. Set the reproduction window at twice that interval, so the test cannot stop just short of the failure.
  3. Remove communications to the PLC for the window and watch the log: handled timeout lines are expected.
  4. Restore communications and confirm the endpoint reconnects, or confirm the crash reproduces first.

One safety note: before you pull that link, get operations' confirmation that the machine tolerates loss of this communications path for the full window, because the test deliberately recreates the outage.

Worked example, with illustrative numbers you replace with your own: the reported log excerpt shows the first transport timeout at 11:30:39 and the exit at 11:31:13, so the visible timeout run lasts 34 seconds, while the reporter places the full failure after minutes of PLC absence. If your log shows the crash arriving after 5 minutes offline, set the window at 10 minutes offline. Five cycles of 10 minutes offline plus 10 minutes of monitoring after restore take 5 × (10 min + 10 min) = 100 minutes of test time. An interval read from a log excerpt undercounts, because the outage began before the first logged timeout; use the outage start, not the first line, when you have it.

How do you verify a fix keeps Node-RED running? #

A fix passes only if Node-RED stays running through the whole disconnect-and-restore test, the log contains zero Uncaught Exception lines, and every S7 endpoint returns to a defined connected state after the PLC comes back, repeated across several cycles to expose cleanup defects.

The pass criteria, case by case:

  • The process survives every cycle. A single exit fails the test, however clean the rest of the log looks.
  • No Uncaught Exception line appears in any cycle. Endpoint-level timeout and disconnected messages during the offline half remain valid and expected; only the escape to the runtime is disqualifying.
  • After restore, the endpoint reaches a connected state and delivers live values, not merely a socket that reports open. A fix that stops the crash but strands the endpoint in a silent half-open state has moved the fault, not fixed it.
  • Successive cycles all pass, because socket cleanup errors often appear only on the second or third reset.

Until a fix clears all four on your target, treat the crash as unresolved, whatever the node's changelog says.

Could the network, not the node, be the real cause? #

The network causes the reset; the node causes the crash: a switch, a cable, or the PLC itself can send the RST that kills one connection, but a correctly written node survives any number of resets, so the handler fix is required whatever the network shows.

Chasing the network is still worth one pass, because it decides what else to fix. When endpoints to several different controllers fail at the same moment, the shared segment, switch, or link is the suspect rather than any single peer; the same simultaneous-drop pattern is documented for OPC UA connections that drop on all controllers at once, and the triage is the same. In the reported case the two S7 endpoints timed out in near lockstep, which points at the path between the Node-RED host and the PLCs, but the crash itself would have happened with any single reset regardless.

The decision, then: report the sequence to the maintainer and hold that owner to the fix, because the reset must be caught inside the node or its dependency. If the maintainer does not respond, fork the node and add the handler, then prove it with the timed disconnect-and-restore test until it passes on repeated cycles. A restart loop on the host is a temporary damper, never the answer, and no Node-RED or flow setting substitutes for the missing handler.

Questions asked

Does restarting Node-RED lose the flows I deployed?

No. On restart the runtime reloads the deployed flows from disk, so your flow configuration survives the crash. What you lose is anything held only in memory at the moment of exit: messages queued between nodes, context a function node kept, and any data the crashed node buffered before the reset. If those gaps matter, buffer upstream at the broker for MQTT traffic or in the source system instead of relying on the process staying up.

Can other protocol nodes stop Node-RED the same way?

Yes. Any node whose socket code lets a reset escape its handler produces the same signature: an Uncaught Exception line followed by read ECONNRESET on TCP.onStreamRead, then an exit. Custom and community protocol nodes are the usual source, because mature protocol stacks handle socket errors internally. The ownership of the fix and the verification test are identical no matter which node leaked the exception.

Why does the stack trace show a different line number on my system?

The path internal/stream_base_commons.js with the function TCP.onStreamRead is the stable part of the trace; the line number, 209 in the reported crash, moves with the Node.js release that runs your Node-RED install, because the runtime's internal stream code changes between versions. Match on the function name and the error text, not the line number, when you compare logs across machines or across a Node.js upgrade.

Is taking the PLC offline for the reproduction test safe?

Only if operations confirms the machine tolerates loss of that communications link for the whole test window. Write down the tags the flow reads, agree the window with the shift before you start, and pick a time when the PLC's own logic does not depend on data returning over that link. Restore communications promptly when the offline half ends and confirm the PLC reports no faults afterward.

Keep reading

  • Troubleshooting

    Why Node-RED crashes at boot with EACCES mkdir //pki on a Linux PLC

    Keep the init.d script — it starts Node-RED correctly. The crash is an uncaught EACCES from the OPC UA client's mkdir of '//pki', a root-level directory the boot-time account cannot write, so fix the service user, HOME, working directory and certificate path instead. The camera's EHOSTUNREACH is a separate reachability fault that never kills the runtime.

    Edge computing and IIoT

  • Troubleshooting

    Sparkplug node stuck on Connecting while MQTT connects

    The node-red-contrib-sparkplug node takes its broker string literally and adds no transport scheme, so a bare IP:port is rejected before any connection attempt and the node sits on Connecting with no error. Write the broker as a full URI — tcp://192.168.1.50:1883 for plaintext or ssl://host:8883 for TLS — deploy, and it connects where the default MQTT node already did.

    Edge computing and IIoT

  • How-to

    Stable Node-RED gateway flows with vendor-pinned nodes

    Yes: install the vendor's SE Modbus and Machine Advisor Node-RED packages from offline files, but only after the installed Yocto image meets the prerequisite in each node's manual. If you keep the template's open-source Modbus node instead, pin it to the example's stated version, 2.5.0.0, and re-verify after any package change.

    Edge computing and IIoT

Why a Snap7 client cannot read a CPU 1507S software controller