EEBus: abort run loop and limit assertion on context cancellation (#32494)

This commit is contained in:
andig 2026-08-03 20:50:34 +02:00 • committed by GitHub
parent 4a878838e7
commit fed3fb731c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 54 additions and 12 deletions

View file

@ -1,6 +1,7 @@
package eebus
import (
"context"
"errors"
"fmt"
"log"
@ -52,10 +53,11 @@ const limitTimeout = 50 * time.Second
// AssertLimit states the current limit to a newly available Controllable System
// ([LPC-913]/[LPP-913]). Blocks while retrying- the CS ignores writes that do not
// follow a heartbeat and may reject them while still in state "init".
func AssertLimit(log *util.Logger, write func() error) {
// follow a heartbeat and may reject them while still in state "init". Retrying
// stops when ctx is cancelled, i.e. when the device is gone.
func AssertLimit(ctx context.Context, log *util.Logger, write func() error) {
bo := backoff.NewExponentialBackOff(backoff.WithMaxElapsedTime(limitTimeout))
if err := backoff.Retry(write, bo); err != nil {
if err := backoff.Retry(write, backoff.WithContext(bo, ctx)); err != nil && ctx.Err() == nil {
log.DEBUG.Printf("assert limit: %v", err)
}
}