Monorepo for Tangled
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

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 <matias@insaurral.de>

authored by

Matías Insaurralde and committed by
Tangled
c354e2f8 ff4bd6c7

+5 -4
+5 -4
knotmirror/resyncer.go
··· 37 37 38 38 knotBackoff map[string]time.Time 39 39 knotBackoffMu sync.RWMutex 40 + 41 + httpClient *http.Client 40 42 } 41 43 42 44 func NewResyncer(l *slog.Logger, db *sql.DB, gitm GitMirrorManager, cfg *config.Config) *Resyncer { ··· 53 55 parallelism: cfg.ResyncParallelism, 54 56 55 57 knotBackoff: make(map[string]time.Time), 58 + 59 + httpClient: &http.Client{Timeout: 30 * time.Second}, 56 60 } 57 61 } 58 62 ··· 283 287 284 288 r.logger.Debug("checking knot reachability", "url", repoUrl) 285 289 286 - client := http.Client{ 287 - Timeout: 30 * time.Second, 288 - } 289 290 req, err := http.NewRequestWithContext(ctx, "GET", repoUrl, nil) 290 291 if err != nil { 291 292 return err ··· 293 294 req.Header.Set("User-Agent", "git/2.x") 294 295 req.Header.Set("Accept", "*/*") 295 296 296 - resp, err := client.Do(req) 297 + resp, err := r.httpClient.Do(req) 297 298 if err != nil { 298 299 var uerr *url.Error 299 300 if errors.As(err, &uerr) {