From c20fbcd842d5ee422171318ddfb249a82833b76b Mon Sep 17 00:00:00 2001 From: Poorna Krishnamoorthy Date: Sun, 27 Jun 2021 10:11:13 -0700 Subject: [PATCH] fix:(replication/bandwidth) add missing validation in monitored reader (#12582) --- cmd/admin-bucket-handlers.go | 2 +- internal/bucket/bandwidth/reader.go | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/cmd/admin-bucket-handlers.go b/cmd/admin-bucket-handlers.go index 401652918..5ebc5d5ef 100644 --- a/cmd/admin-bucket-handlers.go +++ b/cmd/admin-bucket-handlers.go @@ -207,7 +207,7 @@ func (a adminAPIHandlers) SetRemoteTargetHandler(w http.ResponseWriter, r *http. } // enforce minimum bandwidth limit as 100MBps - if target.BandwidthLimit < 100*1000*1000 { + if target.BandwidthLimit > 0 && target.BandwidthLimit < 100*1000*1000 { writeErrorResponseJSON(ctx, w, errorCodes.ToAPIErrWithErr(ErrReplicationBandwidthLimitError, err), r.URL) return } diff --git a/internal/bucket/bandwidth/reader.go b/internal/bucket/bandwidth/reader.go index acc4a2a93..ed143ddae 100644 --- a/internal/bucket/bandwidth/reader.go +++ b/internal/bucket/bandwidth/reader.go @@ -41,11 +41,13 @@ type MonitorReaderOptions struct { // Read implements a throttled read func (r *MonitoredReader) Read(buf []byte) (n int, err error) { + if r.throttle == nil { + return r.r.Read(buf) + } if r.lastErr != nil { err = r.lastErr return } - b := r.throttle.Burst() // maximum available tokens need := len(buf) // number of bytes requested by caller hdr := r.opts.HeaderSize // remaining header bytes