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