mirror of
https://github.com/minio/minio.git
synced 2025-04-04 11:50:36 -04:00
Fix missing GetObjectNInfo Closure (#11243)
Review for missing Close of returned value from `GetObjectNInfo`. This was often obscured by the stuff that auto-unlocks when reaching EOF.
This commit is contained in:
parent
4593b146be
commit
51dad1d130
@ -341,13 +341,13 @@ func transitionObject(ctx context.Context, objectAPI ObjectLayer, objInfo Object
|
|||||||
}
|
}
|
||||||
oi := gr.ObjInfo
|
oi := gr.ObjInfo
|
||||||
if oi.TransitionStatus == lifecycle.TransitionComplete {
|
if oi.TransitionStatus == lifecycle.TransitionComplete {
|
||||||
gr.Close() // make sure to avoid leaks.
|
gr.Close()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
putOpts := putTransitionOpts(oi)
|
putOpts := putTransitionOpts(oi)
|
||||||
if _, err = tgt.PutObject(ctx, arn.Bucket, oi.Name, gr, oi.Size, "", "", putOpts); err != nil {
|
if _, err = tgt.PutObject(ctx, arn.Bucket, oi.Name, gr, oi.Size, "", "", putOpts); err != nil {
|
||||||
gr.Close() // make sure to avoid leaks.
|
gr.Close()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
gr.Close()
|
gr.Close()
|
||||||
|
@ -471,6 +471,8 @@ func replicateObject(ctx context.Context, objInfo ObjectInfo, objectAPI ObjectLa
|
|||||||
for k, v := range putOpts.Header() {
|
for k, v := range putOpts.Header() {
|
||||||
headerSize += len(k) + len(v)
|
headerSize += len(k) + len(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// r takes over closing gr.
|
||||||
r := bandwidth.NewMonitoredReader(ctx, globalBucketMonitor, objInfo.Bucket, objInfo.Name, gr, headerSize, b, target.BandwidthLimit)
|
r := bandwidth.NewMonitoredReader(ctx, globalBucketMonitor, objInfo.Bucket, objInfo.Name, gr, headerSize, b, target.BandwidthLimit)
|
||||||
_, err = tgt.PutObject(ctx, dest.Bucket, object, r, size, "", "", putOpts)
|
_, err = tgt.PutObject(ctx, dest.Bucket, object, r, size, "", "", putOpts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -478,6 +478,7 @@ func (d *dataUsageCache) load(ctx context.Context, store objectIO, name string)
|
|||||||
*d = dataUsageCache{}
|
*d = dataUsageCache{}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
defer r.Close()
|
||||||
if err := d.deserialize(r); err != nil {
|
if err := d.deserialize(r); err != nil {
|
||||||
*d = dataUsageCache{}
|
*d = dataUsageCache{}
|
||||||
logger.LogOnceIf(ctx, err, err.Error())
|
logger.LogOnceIf(ctx, err, err.Error())
|
||||||
|
@ -28,7 +28,7 @@ type MonitoredReader struct {
|
|||||||
bucket string // Token to track bucket
|
bucket string // Token to track bucket
|
||||||
bucketMeasurement *bucketMeasurement // bucket measurement object
|
bucketMeasurement *bucketMeasurement // bucket measurement object
|
||||||
object string // Token to track object
|
object string // Token to track object
|
||||||
reader io.Reader // Reader to wrap
|
reader io.ReadCloser // Reader to wrap
|
||||||
lastStop time.Time // Last timestamp for a measurement
|
lastStop time.Time // Last timestamp for a measurement
|
||||||
headerSize int // Size of the header not captured by reader
|
headerSize int // Size of the header not captured by reader
|
||||||
throttle *throttle // throttle the rate at which replication occur
|
throttle *throttle // throttle the rate at which replication occur
|
||||||
@ -36,8 +36,9 @@ type MonitoredReader struct {
|
|||||||
closed bool // Reader is closed
|
closed bool // Reader is closed
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewMonitoredReader returns a io.ReadCloser that reports bandwidth details
|
// NewMonitoredReader returns a io.ReadCloser that reports bandwidth details.
|
||||||
func NewMonitoredReader(ctx context.Context, monitor *Monitor, bucket string, object string, reader io.Reader, headerSize int, bandwidthBytesPerSecond int64, clusterBandwidth int64) *MonitoredReader {
|
// The supplied reader will be closed.
|
||||||
|
func NewMonitoredReader(ctx context.Context, monitor *Monitor, bucket string, object string, reader io.ReadCloser, headerSize int, bandwidthBytesPerSecond int64, clusterBandwidth int64) *MonitoredReader {
|
||||||
timeNow := time.Now()
|
timeNow := time.Now()
|
||||||
b := monitor.track(bucket, object, timeNow)
|
b := monitor.track(bucket, object, timeNow)
|
||||||
return &MonitoredReader{
|
return &MonitoredReader{
|
||||||
@ -77,10 +78,9 @@ func (m *MonitoredReader) Read(p []byte) (n int, err error) {
|
|||||||
|
|
||||||
// Close stops tracking the io
|
// Close stops tracking the io
|
||||||
func (m *MonitoredReader) Close() error {
|
func (m *MonitoredReader) Close() error {
|
||||||
rc, ok := m.reader.(io.ReadCloser)
|
if m.closed {
|
||||||
m.closed = true
|
return nil
|
||||||
if ok {
|
|
||||||
return rc.Close()
|
|
||||||
}
|
}
|
||||||
return nil
|
m.closed = true
|
||||||
|
return m.reader.Close()
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user