From c354e2f8f94ccd039cec402abd77bdafc8fba2b1 Mon Sep 17 00:00:00 2001 From: Matías Insaurralde Date: Wed, 22 Apr 2026 07:03:25 +0000 Subject: [PATCH] knotmirror/resyncer: reuse http.Client for knot reachability checks Avoid allocating a new http.Client on every resyncRepo call. http.Client is safe for concurrent use and reusing it enables TCP connection pooling across checks to the same knot. Signed-off-by: Matías Insaurralde --- knotmirror/resyncer.go | 9 +++++---- 1 file(s) changed, 5 insertion(s)(+), 4 deletion(s)(-) diff --git a/knotmirror/resyncer.go b/knotmirror/resyncer.go --- a/knotmirror/resyncer.go +++ b/knotmirror/resyncer.go @@ -37,6 +37,8 @@ parallelism int knotBackoff map[string]time.Time knotBackoffMu sync.RWMutex + + httpClient *http.Client } func NewResyncer(l *slog.Logger, db *sql.DB, gitm GitMirrorManager, cfg *config.Config) *Resyncer { @@ -53,6 +55,8 @@ manualResyncTimeout: 30 * time.Minute, parallelism: cfg.ResyncParallelism, knotBackoff: make(map[string]time.Time), + + httpClient: &http.Client{Timeout: 30 * time.Second}, } } @@ -283,9 +287,6 @@ repoUrl += "/info/refs?service=git-upload-pack" r.logger.Debug("checking knot reachability", "url", repoUrl) - client := http.Client{ - Timeout: 30 * time.Second, - } req, err := http.NewRequestWithContext(ctx, "GET", repoUrl, nil) if err != nil { return err @@ -293,7 +294,7 @@ } req.Header.Set("User-Agent", "git/2.x") req.Header.Set("Accept", "*/*") - resp, err := client.Do(req) + resp, err := r.httpClient.Do(req) if err != nil { var uerr *url.Error if errors.As(err, &uerr) { -- tangled.sh