Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions cache/httpproxy/httpproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ var (
func (r *remoteHTTPProxyCache) UploadFile(item backendproxy.UploadReq) {

if item.LogicalSize == 0 {
item.Rc.Close()
_ = item.Rc.Close()
// See https://github.com/golang/go/issues/20257#issuecomment-299509391
item.Rc = http.NoBody
}
Expand All @@ -54,14 +54,14 @@ func (r *remoteHTTPProxyCache) UploadFile(item backendproxy.UploadReq) {
req, err := http.NewRequestWithContext(context.Background(), http.MethodHead, url, nil)
if err != nil {
r.errorLogger.Printf("INTERNAL ERROR, FAILED TO SETUP HTTP PROXY UPLOAD %s: %s", url, err)
item.Rc.Close()
_ = item.Rc.Close()
return
}

rsp, err := r.remote.Do(req)
if err == nil && rsp.StatusCode == http.StatusOK {
r.accessLogger.Printf("SKIP UPLOAD %s", item.Hash)
item.Rc.Close()
_ = item.Rc.Close()
return
}

Expand All @@ -71,7 +71,7 @@ func (r *remoteHTTPProxyCache) UploadFile(item backendproxy.UploadReq) {

// item.Rc will be closed if we call req.Do(), but not if we
// return earlier.
item.Rc.Close()
_ = item.Rc.Close()

return
}
Expand All @@ -88,7 +88,7 @@ func (r *remoteHTTPProxyCache) UploadFile(item backendproxy.UploadReq) {
r.errorLogger.Printf("HTTP %s UPLOAD: %s", url, err.Error())
return
}
rsp.Body.Close()
_ = rsp.Body.Close()

logResponse(r.accessLogger, "UPLOAD", rsp.StatusCode, url)
}
Expand All @@ -108,21 +108,21 @@ func New(baseURL *url.URL, storageMode string, remote *http.Client,
v2mode: storageMode == "zstd",
}

if storageMode == "zstd" {
switch storageMode {
case "zstd":
proxy.requestURL = func(hash string, kind cache.EntryKind) string {
if kind == cache.CAS {
return fmt.Sprintf("%s/cas.v2/%s", proxy.baseURL, hash)
}

return fmt.Sprintf("%s/%s/%s", proxy.baseURL, kind, hash)
}
} else if storageMode == "uncompressed" {
case "uncompressed":
proxy.requestURL = func(hash string, kind cache.EntryKind) string {
return fmt.Sprintf("%s/%s/%s", proxy.baseURL, kind, hash)
}
} else {
return nil, fmt.Errorf("Invalid http_proxy.mode specified: %q",
storageMode)
default:
return nil, fmt.Errorf("invalid http_proxy.mode specified: %q", storageMode)
}

proxy.uploadQueue = backendproxy.StartUploaders(proxy, numUploaders, maxQueuedUploads)
Expand All @@ -137,7 +137,7 @@ func logResponse(logger cache.Logger, method string, code int, url string) {

func (r *remoteHTTPProxyCache) Put(ctx context.Context, kind cache.EntryKind, hash string, logicalSize int64, sizeOnDisk int64, rc io.ReadCloser) {
if r.uploadQueue == nil {
rc.Close()
_ = rc.Close()
return
}

Expand All @@ -153,7 +153,7 @@ func (r *remoteHTTPProxyCache) Put(ctx context.Context, kind cache.EntryKind, ha
case r.uploadQueue <- item:
default:
r.errorLogger.Printf("too many uploads queued")
rc.Close()
_ = rc.Close()
}
}

Expand Down Expand Up @@ -203,7 +203,7 @@ func (r *remoteHTTPProxyCache) Get(ctx context.Context, kind cache.EntryKind, ha

sizeBytesStr := rsp.Header.Get("Content-Length")
if sizeBytesStr == "" {
err = errors.New("Missing Content-Length header")
err = errors.New("missing Content-Length header")
cacheMisses.Inc()
return nil, -1, err
}
Expand Down
27 changes: 15 additions & 12 deletions cache/httpproxy/httpproxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,18 @@ func (s *testServer) handler(w http.ResponseWriter, r *http.Request) {

kind := fields[1]
var kindMap map[string][]byte
if kind == "ac" {

switch kind {
case "ac":
kindMap = s.ac
} else if kind == "cas.v2" {
case "cas.v2":
kindMap = s.cas
} else {
default:
msg := fmt.Sprintf("unsupported URL: %q", r.URL.Path)
http.Error(w, msg, http.StatusBadRequest)
return
}

hash := fields[2]

s.mu.Lock()
Expand Down Expand Up @@ -99,7 +102,7 @@ func TestEverything(t *testing.T) {
defer s.srv.Close()

cacheDir := testutils.TempDir(t)
defer os.RemoveAll(cacheDir)
defer func() { _ = os.RemoveAll(cacheDir) }()

logFlags := log.Ldate | log.Ltime | log.LUTC
accessLogger := log.New(os.Stdout, "", logFlags)
Expand Down Expand Up @@ -177,7 +180,7 @@ func TestEverything(t *testing.T) {
t.Fatal(err)
}
tfn := tmpfile.Name()
defer os.Remove(tfn)
defer func() { _ = os.Remove(tfn) }()

_, err = io.Copy(tmpfile, bytes.NewReader(v))
if err != nil {
Expand All @@ -187,7 +190,7 @@ func TestEverything(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer os.Remove(tmpfile2.Name())
defer func() { _ = os.Remove(tmpfile2.Name()) }()

var zi zstdimpl.ZstdImpl
zi, err = zstdimpl.Get("go")
Expand All @@ -200,7 +203,7 @@ func TestEverything(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer rc.Close()
defer func() { _ = rc.Close() }()
vData, err := io.ReadAll(rc)
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -259,7 +262,7 @@ func TestEverything(t *testing.T) {
if !bytes.Equal(data, acData) {
t.Error("Different AC data returned")
}
rc.Close()
_ = rc.Close()

rc, size, err = diskCache.Get(ctx, cache.CAS, hash, int64(len(casData)), 0)
if err != nil {
Expand All @@ -279,13 +282,13 @@ func TestEverything(t *testing.T) {
if !bytes.Equal(data, casData) {
t.Error("Different CAS data returned")
}
rc.Close()
_ = rc.Close()

// Create a new empty cache, and check that we can fill it
// from the backend.

cacheDir2 := testutils.TempDir(t)
defer os.RemoveAll(cacheDir2)
defer func() { _ = os.RemoveAll(cacheDir2) }()

diskCache, err = disk.New(cacheDir2, diskCacheSize, disk.WithProxyBackend(proxyCache), disk.WithAccessLogger(testutils.NewSilentLogger()))
if err != nil {
Expand Down Expand Up @@ -337,7 +340,7 @@ func TestEverything(t *testing.T) {
if !bytes.Equal(data, acData) {
t.Error("Different AC data returned")
}
rc.Close()
_ = rc.Close()

rc, size, err = diskCache.Get(ctx, cache.CAS, hash, int64(len(casData)), 0)
if err != nil {
Expand All @@ -357,5 +360,5 @@ func TestEverything(t *testing.T) {
if !bytes.Equal(data, casData) {
t.Error("Different CAS data returned")
}
rc.Close()
_ = rc.Close()
}