From c0bb9a3fed31907cf9854fc2fd6d19e3e7f6d86f Mon Sep 17 00:00:00 2001 From: Michael Geers Date: Thu, 6 Aug 2026 07:21:44 +0200 Subject: [PATCH] Sponsor: wait for network to settle during startup check (#32556) --- util/sponsor/auth.go | 8 ++++++-- util/sponsor/hardware.go | 6 +++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/util/sponsor/auth.go b/util/sponsor/auth.go index c29cbc23b..63107af3e 100644 --- a/util/sponsor/auth.go +++ b/util/sponsor/auth.go @@ -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() diff --git a/util/sponsor/hardware.go b/util/sponsor/hardware.go index ae2c35642..82ea73ad9 100644 --- a/util/sponsor/hardware.go +++ b/util/sponsor/hardware.go @@ -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