From c2534c19f67f8edd6a4a034d84ac49967e7416d5 Mon Sep 17 00:00:00 2001 From: Callum Styan Date: Tue, 10 Mar 2026 10:33:49 -0700 Subject: [PATCH] feat: add codersdk constructor that uses an independent transport (#22282) This is useful at least in the case of scaletests but potentially in other places as well. I noticed that scaletest workspace creation hammers a single coderd replica. --------- Signed-off-by: Callum Styan --- scaletest/createusers/run.go | 8 +++++++- scaletest/createworkspaces/run.go | 9 ++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/scaletest/createusers/run.go b/scaletest/createusers/run.go index 3ed692a5f2..78f648f1bc 100644 --- a/scaletest/createusers/run.go +++ b/scaletest/createusers/run.go @@ -76,7 +76,13 @@ func (r *Runner) RunReturningUser(ctx context.Context, id string, logs io.Writer r.user = user _, _ = fmt.Fprintln(logs, "\nLogging in as new user...") - client := codersdk.New(r.client.URL) + // Duplicate the client with an independent transport to ensure each user + // login gets its own HTTP connection pool, preventing connection sharing + // during load testing. + client, err := loadtestutil.DupClientCopyingHeaders(r.client, nil) + if err != nil { + return User{}, xerrors.Errorf("duplicate client: %w", err) + } loginRes, err := client.LoginWithPassword(ctx, codersdk.LoginWithPasswordRequest{ Email: r.cfg.Email, Password: password, diff --git a/scaletest/createworkspaces/run.go b/scaletest/createworkspaces/run.go index 2a63588fc0..56eaaa7778 100644 --- a/scaletest/createworkspaces/run.go +++ b/scaletest/createworkspaces/run.go @@ -77,7 +77,14 @@ func (r *Runner) Run(ctx context.Context, id string, logs io.Writer) error { return xerrors.Errorf("create user: %w", err) } user = newUser.User - client = codersdk.New(r.client.URL) + // Duplicate the client with an independent transport to ensure each + // workspace creation gets its own HTTP connection pool. This prevents + // HTTP/2 connection multiplexing from causing all workspace GET requests + // to route to a single backend pod during load testing. + client, err = loadtestutil.DupClientCopyingHeaders(r.client, nil) + if err != nil { + return xerrors.Errorf("duplicate client: %w", err) + } client.SetSessionToken(newUser.SessionToken) }