Skip to content

Commit

Permalink
Merge pull request #208 from BenTheElder/cache
Browse files Browse the repository at this point in the history
set timeout for bucket HEAD client
  • Loading branch information
k8s-ci-robot authored Apr 18, 2023
2 parents 74d6875 + 918947d commit e9c6c92
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions cmd/archeio/internal/app/buckets.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package app
import (
"net/http"
"sync"
"time"

"k8s.io/klog/v2"
)
Expand Down Expand Up @@ -82,7 +83,7 @@ type blobChecker interface {
// TODO: potentially replace with a caching implementation
// should be plenty fast for now, HTTP HEAD on s3 is cheap
type cachedBlobChecker struct {
http.Client
client *http.Client
blobCache
}

Expand All @@ -91,6 +92,15 @@ func newCachedBlobChecker() *cachedBlobChecker {
blobCache: blobCache{
cache: make(map[string]map[string]struct{}),
},
client: newHTTPClient(),
}
}

func newHTTPClient() *http.Client {
// ensure sensible timeouts
// this client will be used to make HEAD calls
return &http.Client{
Timeout: time.Second * 5,
}
}

Expand Down Expand Up @@ -127,7 +137,7 @@ func (c *cachedBlobChecker) BlobExists(blobURL, bucket, layerHash string) bool {
return true
}
klog.V(3).InfoS("blob existence cache miss", "url", blobURL)
r, err := c.Client.Head(blobURL)
r, err := c.client.Head(blobURL)
// fallback to assuming blob is unavailable on errors
if err != nil {
return false
Expand Down

0 comments on commit e9c6c92

Please sign in to comment.