Sponsor: wait for network to settle during startup check [0.313 backport] (#32557)
Some checks failed
Release / call-build-workflow (push) Has been cancelled
Release / Publish Docker :release (push) Has been cancelled
Release / Github & APT (push) Has been cancelled
Release / Demo (push) Has been cancelled
Release / Hassio Addon (push) Has been cancelled

This commit is contained in:
Michael Geers 2026-08-06 08:38:05 +02:00 • committed by GitHub
parent 4ca64eaf49
commit 5b4b4a333c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 5 deletions

View file

@ -30,6 +30,7 @@ import (
"github.com/evcc-io/evcc/util/cloud"
"github.com/evcc-io/evcc/util/machine"
"github.com/golang-jwt/jwt/v5"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
@ -46,6 +47,9 @@ func machineID() string {
const unavailable = "sponsorship unavailable"
// startupTimeout leaves the network time to settle at boot; grpc retries dialing with backoff until deadline
const startupTimeout = 30 * time.Second
func IsAuthorized() bool {
mu.RLock()
defer mu.RUnlock()
@ -98,10 +102,10 @@ func ConfigureSponsorship(token string) error {
client := pb.NewAuthClient(conn)
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
ctx, cancel := context.WithTimeout(context.Background(), startupTimeout)
defer cancel()
res, err := client.IsAuthorized(ctx, &pb.AuthRequest{Token: token, MachineId: machineID()})
res, err := client.IsAuthorized(ctx, &pb.AuthRequest{Token: token, MachineId: machineID()}, grpc.WaitForReady(true))
if err == nil && res.Authorized {
Subject = res.Subject
ExpiresAt = res.ExpiresAt.AsTime()

View file

@ -22,7 +22,7 @@ import (
"github.com/evcc-io/evcc/api/proto/pb"
"github.com/evcc-io/evcc/util/cloud"
"github.com/evcc-io/evcc/util/request"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
@ -34,7 +34,7 @@ func checkHardware(vendor string, metadata map[string]string) string {
return unavailable
}
ctx, cancel := context.WithTimeout(context.Background(), request.Timeout)
ctx, cancel := context.WithTimeout(context.Background(), startupTimeout)
defer cancel()
client := pb.NewAuthClient(conn)
@ -42,7 +42,7 @@ func checkHardware(vendor string, metadata map[string]string) string {
MachineId: machineID(),
Vendor: vendor,
Metadata: metadata,
})
}, grpc.WaitForReady(true))
if err == nil && res.Authorized {
return res.Subject