Fix potential busy loop with short timeouts (#9320)

This commit is contained in:
andig 2023-08-10 08:48:54 +02:00 • committed by GitHub
parent 7a314c79ee
commit d883a1bfe1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 6 additions and 6 deletions

View file

@ -104,7 +104,7 @@ func NewDaheimLadenMB(uri string, id uint8) (api.Charger, error) {
return nil, fmt.Errorf("failsafe timeout: %w", err)
}
if u := binary.BigEndian.Uint16(b); u > 0 {
go wb.heartbeat(time.Duration(u/2) * time.Second)
go wb.heartbeat(time.Duration(u) * time.Second / 2)
}
return wb, err

View file

@ -117,11 +117,11 @@ func NewKebaFromConfig(other map[string]interface{}) (api.Charger, error) {
// failsafe
b, err = wb.conn.ReadHoldingRegisters(kebaRegFailsafeTimeout, 2)
if err != nil {
return nil, err
return nil, fmt.Errorf("failsafe timeout: %w", err)
}
if timeout := binary.BigEndian.Uint32(b); timeout > 0 {
go wb.heartbeat(900 * time.Millisecond * time.Duration(timeout))
if u := binary.BigEndian.Uint32(b); u > 0 {
go wb.heartbeat(time.Duration(u) * time.Second / 2)
}
return decorateKeba(wb, currentPower, totalEnergy, currents, identify, phases), nil

View file

@ -63,7 +63,7 @@ func NewObo(uri, device, comset string, baudrate int, proto modbus.Protocol, sla
return nil, fmt.Errorf("failsafe timeout: %w", err)
}
if u := binary.BigEndian.Uint16(b); u > 0 {
go wb.heartbeat(time.Duration(u/2) * time.Millisecond)
go wb.heartbeat(time.Duration(u) * time.Millisecond / 2)
}
// lightshow

View file

@ -98,7 +98,7 @@ func NewWebastoNext(uri string, id uint8) (api.Charger, error) {
return nil, fmt.Errorf("failsafe timeout: %w", err)
}
if u := binary.BigEndian.Uint16(b); u > 0 {
go wb.heartbeat(time.Duration(u/2) * time.Second)
go wb.heartbeat(time.Duration(u) * time.Second / 2)
}
return wb, err