From 3823bf5be928aff43a9cac3dde0b0210b5387c86 Mon Sep 17 00:00:00 2001 From: mlsmaycon Date: Fri, 4 Sep 2026 04:27:56 +0200 Subject: [PATCH] [client] Keep the device name on the context used to authenticate Moving authentication onto the start context dropped the device name with it: registration happens during login and reads the name from the context, so every client registered under the host's hostname instead of its configured name. A run of 100 embedded clients produced 191 peers all sharing one name. Carry the value onto the start context explicitly so the deadline and the device name travel together. --- client/embed/embed.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/client/embed/embed.go b/client/embed/embed.go index 543ec9561..8e1ecca77 100644 --- a/client/embed/embed.go +++ b/client/embed/embed.go @@ -305,13 +305,18 @@ func (c *Client) Start(startCtx context.Context) error { // never completes a stream leaves them retrying with no deadline of their // own, so a caller's start timeout has to reach them. Neither outlives // startup: authClient is closed below. - authClient, err := auth.NewAuth(startCtx, c.config.PrivateKey, c.config.ManagementURL, c.config) + // Carry the device name onto the start context: registration happens during + // login and reads it from there, so authenticating on a context without it + // would register every client under the host's hostname instead. + authCtx := context.WithValue(startCtx, system.DeviceNameCtxKey, c.deviceName) //nolint:staticcheck + + authClient, err := auth.NewAuth(authCtx, c.config.PrivateKey, c.config.ManagementURL, c.config) if err != nil { return fmt.Errorf("create auth client: %w", err) } defer authClient.Close() - if err, _ := authClient.Login(startCtx, c.setupKey, c.jwtToken); err != nil { + if err, _ := authClient.Login(authCtx, c.setupKey, c.jwtToken); err != nil { return fmt.Errorf("login: %w", err) } client := internal.NewConnectClient(ctx, c.config, c.recorder)