fix:(replication/bandwidth) add missing validation in monitored reader (#12582)

This commit is contained in:
Poorna Krishnamoorthy 2021-06-27 10:11:13 -07:00 committed by GitHub
parent 36110fbc77
commit c20fbcd842
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 2 deletions

View file

@ -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
}

View file

@ -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