Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
wzshiming committed Jun 20, 2024
1 parent 0712c25 commit 114583d
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions crproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ func (c *CRProxy) cacheBlobResponse(rw http.ResponseWriter, r *http.Request, inf

go func() {
defer doneCache()
size, err := c.cacheBlobContent(r, blobPath, info)
size, err := c.cacheBlobContent(context.Background(), r, blobPath, info)
signalCh <- repo{
err: err,
size: size,
Expand Down Expand Up @@ -698,9 +698,9 @@ func (c *CRProxy) cacheBlobResponse(rw http.ResponseWriter, r *http.Request, inf
}
}

func (c *CRProxy) cacheBlobContent(r *http.Request, blobPath string, info *PathInfo) (int64, error) {
func (c *CRProxy) cacheBlobContent(ctx context.Context, r *http.Request, blobPath string, info *PathInfo) (int64, error) {
cli := c.getClientset(info.Host, info.Image)
resp, err := c.doWithAuth(cli, r, info.Host)
resp, err := c.doWithAuth(cli, r.WithContext(ctx), info.Host)
if err != nil {
return 0, err
}
Expand All @@ -719,7 +719,7 @@ func (c *CRProxy) cacheBlobContent(r *http.Request, blobPath string, info *PathI
buf := c.bytesPool.Get().([]byte)
defer c.bytesPool.Put(buf)

fw, err := c.storageDriver.Writer(context.Background(), blobPath, false)
fw, err := c.storageDriver.Writer(ctx, blobPath, false)
if err != nil {
return 0, err
}
Expand Down Expand Up @@ -753,7 +753,7 @@ func (c *CRProxy) errorResponse(rw http.ResponseWriter, r *http.Request, err err
if err != nil {
e := err.Error()
if c.logger != nil {
c.logger.Println(e)
c.logger.Println("error response", r.RemoteAddr, e)
}
}

Expand Down Expand Up @@ -826,13 +826,15 @@ func (c *CRProxy) checkLimit(rw http.ResponseWriter, r *http.Request, info *Path
func (c *CRProxy) waitForLimit(r *http.Request, info *PathInfo, size int64) bool {
if c.blobsSpeedLimit != nil && info.Blobs != "" {
dur := GetSleepDuration(geario.B(size), *c.blobsSpeedLimit, c.blobsSpeedLimitDuration)
if c.logger != nil {
c.logger.Println("delay request", geario.B(size), dur)
}
select {
case <-r.Context().Done():
return false
case <-time.After(dur):
if dur > 0 {
if c.logger != nil {
c.logger.Println("delay request", r.RemoteAddr, geario.B(size), dur)
}
select {
case <-r.Context().Done():
return false
case <-time.After(dur):
}
}
}

Expand Down

0 comments on commit 114583d

Please sign in to comment.