Sponsor: wait for network to settle during startup check (#32556)

This commit is contained in:
Michael Geers 2026-08-06 07:21:44 +02:00 • committed by GitHub
parent 38ec8d711c
commit c0bb9a3fed
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