Skip to content

Commit

Permalink
fileserver: Add a few more debug lines (#4063)
Browse files Browse the repository at this point in the history
  • Loading branch information
francislavoie authored Mar 19, 2021
1 parent a48c620 commit 0018b9b
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions modules/caddyhttp/fileserver/staticfiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,15 +295,18 @@ func (fsrv *FileServer) openFile(filename string, w http.ResponseWriter) (*os.Fi
if err != nil {
err = mapDirOpenError(err, filename)
if os.IsNotExist(err) {
fsrv.logger.Debug("file not found", zap.String("filename", filename), zap.Error(err))
return nil, caddyhttp.Error(http.StatusNotFound, err)
} else if os.IsPermission(err) {
fsrv.logger.Debug("permission denied", zap.String("filename", filename), zap.Error(err))
return nil, caddyhttp.Error(http.StatusForbidden, err)
}
// maybe the server is under load and ran out of file descriptors?
// have client wait arbitrary seconds to help prevent a stampede
//nolint:gosec
backoff := weakrand.Intn(maxBackoff-minBackoff) + minBackoff
w.Header().Set("Retry-After", strconv.Itoa(backoff))
fsrv.logger.Debug("retry after backoff", zap.String("filename", filename), zap.Int("backoff", backoff), zap.Error(err))
return nil, caddyhttp.Error(http.StatusServiceUnavailable, err)
}
return file, nil
Expand Down

0 comments on commit 0018b9b

Please sign in to comment.