From 67eca6456ddd6dfee96b955f096f6d3028ca40d1 Mon Sep 17 00:00:00 2001 From: Fredrik Ahlgren Date: Wed, 28 Oct 2026 06:11:40 +0100 Subject: [PATCH] fix(modbus): reach a returning device within 10 s The reconnect backoff grew to 60 s. After an outage the inverter could hold its last forced battery mode for up to a minute before Core reached it again (rig R8; seeds show 40 to 123 s past the 10 s line). The owner set the line at 10 s on 28 Oct. A dead endpoint now costs one connect attempt per 10 s, under the 10-per-minute eviction warning. Co-Authored-By: Claude Opus 5.5 --- .changeset/modbus-reconnect-10s.md | 5 +++++ go/internal/modbus/client.go | 5 ++++- go/internal/modbus/client_test.go | 8 ++++---- 3 files changed, 13 insertions(+), 5 deletions(-) create mode 100644 .changeset/modbus-reconnect-10s.md diff --git a/.changeset/modbus-reconnect-10s.md b/.changeset/modbus-reconnect-10s.md new file mode 100644 index 000000000..44322faef --- /dev/null +++ b/.changeset/modbus-reconnect-10s.md @@ -0,0 +1,5 @@ +--- +"ftw": patch +--- + +A Modbus device that comes back after an outage is reached within 10 s. Core used to wait up to 60 s between reconnect attempts, so an inverter could hold its last forced battery mode for a minute after it returned. diff --git a/go/internal/modbus/client.go b/go/internal/modbus/client.go index 60fcbf0b2..393c537ae 100644 --- a/go/internal/modbus/client.go +++ b/go/internal/modbus/client.go @@ -21,7 +21,10 @@ import ( const ( reconnectBackoffBase = 2 * time.Second - reconnectBackoffMax = 60 * time.Second + // A device that comes back must be reached within 10 s: until then it + // may hold the last forced battery mode. A dead endpoint costs one + // connect attempt per 10 s, well under the eviction threshold below. + reconnectBackoffMax = 10 * time.Second // Many inverters accept exactly one Modbus TCP session and evict the // previous one on every new connect. Redials above this rate almost diff --git a/go/internal/modbus/client_test.go b/go/internal/modbus/client_test.go index 8050c592d..44de23120 100644 --- a/go/internal/modbus/client_test.go +++ b/go/internal/modbus/client_test.go @@ -474,10 +474,10 @@ func TestReconnectBackoffSchedule(t *testing.T) { 2: 2 * time.Second, 3: 4 * time.Second, 4: 8 * time.Second, - 5: 16 * time.Second, - 6: 32 * time.Second, - 7: 60 * time.Second, - 8: 60 * time.Second, + 5: 10 * time.Second, + 6: 10 * time.Second, + 7: 10 * time.Second, + 8: 10 * time.Second, } for failures, delay := range want { c.consecutiveTransportFailures = failures