Repository navigation
fix(modbus): reconnect on transport errors (Sungrow silent-zeros bug) - #125
Merged
Merged
Conversation
simonvetter/modbus doesn't self-heal from a closed TCP socket: subsequent reads return errors forever until Open() is called again. Observed on 2026-04-19 on Fredrik's Sungrow SH10RT — after the driver's watchdog-triggered write at startup, the inverter silently dropped the TCP connection and every driver_poll's 23 modbus_reads returned errors (caught by Lua pcall silently). The driver kept emitting zeros for PV, battery, meter, and SoC for hours until a manual driver restart. SoC reporting for the Sungrow got stuck at its pre-disconnect value while the inverter autonomously discharged down below the configured 10 % floor. Capability.Read / WriteSingle / WriteMulti now classify errors: - Transport errors (EOF, ECONNRESET, EPIPE, i/o timeout, net.Error with Timeout=true, plus a narrow string-match allowlist for messages simonvetter wraps as plain errors) → reconnect + retry once. - Modbus protocol errors (illegal address / function / slave busy) → bubble up; the peer is alive, connection is fine. Test stands up a toy TCP server that responds once then closes; verifies the second Read succeeds via reconnect. isTransportError classifier has its own truth table. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
2 of 3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
On 2026-04-19 Fredrik's Sungrow SH10RT silently stopped reporting telemetry — pv/bat/meter/SoC all stuck at zero for hours, SoC slowly draining below the configured 10 % floor with no visibility. Root cause: after our watchdog-triggered write at startup, the inverter's TCP Modbus server dropped the session. The simonvetter/modbus client does not auto-reopen — subsequent
ReadRegisterscalls return transport errors untilOpen()is called again. Our driver'spcallaroundhost.modbus_readcaught those errors silently and emitted zeros. A manual driver-restart fixed it, confirming the theory.Fix
Capability.Read / WriteSingle / WriteMultinow classify errors:EOF,ECONNRESET,EPIPE,i/o timeout,net.Error.Timeout=true, plus a narrow allowlist of simonvetter's wrapped string-errors) → reconnect + retry onceTest plan
isTransportErrortruth table (10 cases)Readreconnects and returns the next queued valuego test ./...incl. e2e stays green🤖 Generated with Claude Code