Monorepo for Tangled tangled.org
772
fork

Configure Feed

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

knotmirror: reuse http.Client in resyncer #28

Summary#

  • Move http.Client from per-call allocation in checkKnotReachability to a shared field on Resyncer.
  • http.Client is safe for concurrent use and reusing it enables TCP connection pooling across reachability checks to the same knot.
Labels

None yet.

assignee

None yet.

Participants 1
AT URI
at://did:plc:wtmr5brxfbwmb666krk4y75r/sh.tangled.repo.pull/3mk55yazy2c22
+5 -4
Diff #0
+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) {

History

1 round 0 comments
sign up or login to add to the discussion
matias.tngl.sh submitted #0
1 commit
expand
knotmirror/resyncer: reuse http.Client for knot reachability checks
merge conflicts detected
expand
  • knotmirror/resyncer.go:37
expand 0 comments