diff --git a/weed/server/filer_server_handlers.go b/weed/server/filer_server_handlers.go index 0389e1e18..118646a04 100644 --- a/weed/server/filer_server_handlers.go +++ b/weed/server/filer_server_handlers.go @@ -58,8 +58,8 @@ func (fs *FilerServer) filerHandler(w http.ResponseWriter, r *http.Request) { glog.V(4).Infof("wait because inflight data %d > %d", fs.inFlightDataSize, fs.option.ConcurrentUploadLimit) fs.inFlightDataLimitCond.Wait() } - atomic.AddInt64(&fs.inFlightDataSize, contentLength) fs.inFlightDataLimitCond.L.Unlock() + atomic.AddInt64(&fs.inFlightDataSize, contentLength) defer func() { atomic.AddInt64(&fs.inFlightDataSize, -contentLength) fs.inFlightDataLimitCond.Signal() diff --git a/weed/server/volume_server_handlers.go b/weed/server/volume_server_handlers.go index ed7807bb8..ff2eccc11 100644 --- a/weed/server/volume_server_handlers.go +++ b/weed/server/volume_server_handlers.go @@ -42,6 +42,7 @@ func (vs *VolumeServer) privateStoreHandler(w http.ResponseWriter, r *http.Reque glog.V(4).Infof("wait because inflight download data %d > %d", vs.inFlightDownloadDataSize, vs.concurrentDownloadLimit) vs.inFlightDownloadDataLimitCond.Wait() } + vs.inFlightDownloadDataLimitCond.L.Unlock() vs.GetOrHeadHandler(w, r) case "DELETE": stats.DeleteRequest() @@ -55,8 +56,8 @@ func (vs *VolumeServer) privateStoreHandler(w http.ResponseWriter, r *http.Reque glog.V(4).Infof("wait because inflight upload data %d > %d", vs.inFlightUploadDataSize, vs.concurrentUploadLimit) vs.inFlightUploadDataLimitCond.Wait() } - atomic.AddInt64(&vs.inFlightUploadDataSize, contentLength) vs.inFlightUploadDataLimitCond.L.Unlock() + atomic.AddInt64(&vs.inFlightUploadDataSize, contentLength) defer func() { atomic.AddInt64(&vs.inFlightUploadDataSize, -contentLength) vs.inFlightUploadDataLimitCond.Signal() @@ -92,11 +93,14 @@ func (vs *VolumeServer) publicReadOnlyHandler(w http.ResponseWriter, r *http.Req w.Header().Set("Access-Control-Allow-Credentials", "true") } switch r.Method { - case "GET": - stats.ReadRequest() - vs.GetOrHeadHandler(w, r) - case "HEAD": + case "GET", "HEAD": stats.ReadRequest() + vs.inFlightDownloadDataLimitCond.L.Lock() + for vs.concurrentDownloadLimit != 0 && atomic.LoadInt64(&vs.inFlightDownloadDataSize) > vs.concurrentDownloadLimit { + glog.V(4).Infof("wait because inflight download data %d > %d", vs.inFlightDownloadDataSize, vs.concurrentDownloadLimit) + vs.inFlightDownloadDataLimitCond.Wait() + } + vs.inFlightDownloadDataLimitCond.L.Unlock() vs.GetOrHeadHandler(w, r) case "OPTIONS": stats.ReadRequest() diff --git a/weed/server/volume_server_handlers_read.go b/weed/server/volume_server_handlers_read.go index ae3c0b53f..8602b0854 100644 --- a/weed/server/volume_server_handlers_read.go +++ b/weed/server/volume_server_handlers_read.go @@ -129,7 +129,6 @@ func (vs *VolumeServer) GetOrHeadHandler(w http.ResponseWriter, r *http.Request) onReadSizeFn := func(size types.Size) { needleSize = size atomic.AddInt64(&vs.inFlightDownloadDataSize, int64(needleSize)) - vs.inFlightDownloadDataLimitCond.L.Unlock() } if hasVolume { count, err = vs.store.ReadVolumeNeedle(volumeId, n, readOption, onReadSizeFn)