Config: bound device check value probing with context (#31115)

This commit is contained in:
andig 2026-06-22 11:11:24 +02:00 • committed by GitHub
parent 6cd9ddb63b
commit e3b1340513
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 202 additions and 149 deletions

View file

@ -9,6 +9,7 @@ import (
"reflect"
"slices"
"strconv"
"time"
"dario.cat/mergo"
"github.com/evcc-io/evcc/api/globalconfig"
@ -280,7 +281,11 @@ func deviceStatusHandler(w http.ResponseWriter, r *http.Request) {
return
}
jsonWrite(w, testInstance(instance))
// bound the value-probe phase so a blocking getter cannot stall the response
ctx, cancel := context.WithTimeout(r.Context(), 10*time.Second)
defer cancel()
jsonWrite(w, testInstance(ctx, instance))
}
func newDevice[T any](ctx context.Context, class templates.Class, req configReq, newFromConf newFromConfFunc[T], h config.Handler[T], force bool) (*config.Config, error) {
@ -697,5 +702,9 @@ func testConfigHandler(w http.ResponseWriter, r *http.Request) {
close(done)
defer cancel()
jsonWrite(w, testInstance(instance))
// bound the value-probe phase so a blocking getter cannot stall the response
probeCtx, probeCancel := context.WithTimeout(r.Context(), 10*time.Second)
defer probeCancel()
jsonWrite(w, testInstance(probeCtx, instance))
}