From 3c8fabd116a3604ad928d15fc382b32124901e89 Mon Sep 17 00:00:00 2001 From: Aditya Manthramurthy Date: Fri, 21 Sep 2018 11:42:06 -0700 Subject: [PATCH] Fix cleanup of pipe in GetObjectNInfo handlers (#6509) --- cmd/disk-cache.go | 3 ++- cmd/gateway/azure/gateway-azure.go | 5 ++++- cmd/gateway/b2/gateway-b2.go | 5 ++++- cmd/gateway/gcs/gateway-gcs.go | 5 ++++- cmd/gateway/manta/gateway-manta.go | 5 ++++- cmd/gateway/oss/gateway-oss.go | 5 ++++- cmd/gateway/s3/gateway-s3.go | 5 ++++- cmd/gateway/sia/gateway-sia.go | 5 ++++- cmd/xl-v1-object.go | 5 ++++- 9 files changed, 34 insertions(+), 9 deletions(-) diff --git a/cmd/disk-cache.go b/cmd/disk-cache.go index d735fef99..7736f3d14 100644 --- a/cmd/disk-cache.go +++ b/cmd/disk-cache.go @@ -259,7 +259,8 @@ func (c cacheObjects) GetObjectNInfo(ctx context.Context, bucket, object string, }() cleanupBackend := func() { bkReader.Close() } - gr = NewGetObjectReaderFromReader(teeReader, bkReader.ObjInfo, cleanupBackend) + cleanupPipe := func() { pipeReader.Close() } + gr = NewGetObjectReaderFromReader(teeReader, bkReader.ObjInfo, cleanupBackend, cleanupPipe) return gr, nil } diff --git a/cmd/gateway/azure/gateway-azure.go b/cmd/gateway/azure/gateway-azure.go index c1f92900e..c6ecb48f6 100644 --- a/cmd/gateway/azure/gateway-azure.go +++ b/cmd/gateway/azure/gateway-azure.go @@ -634,7 +634,10 @@ func (a *azureObjects) GetObjectNInfo(ctx context.Context, bucket, object string err := a.GetObject(ctx, bucket, object, startOffset, length, pw, objInfo.ETag, minio.ObjectOptions{}) pw.CloseWithError(err) }() - return minio.NewGetObjectReaderFromReader(pr, objInfo), nil + // Setup cleanup function to cause the above go-routine to + // exit in case of partial read + pipeCloser := func() { pr.Close() } + return minio.NewGetObjectReaderFromReader(pr, objInfo, pipeCloser), nil } // GetObject - reads an object from azure. Supports additional diff --git a/cmd/gateway/b2/gateway-b2.go b/cmd/gateway/b2/gateway-b2.go index 440799f55..64d2a7e4c 100644 --- a/cmd/gateway/b2/gateway-b2.go +++ b/cmd/gateway/b2/gateway-b2.go @@ -414,7 +414,10 @@ func (l *b2Objects) GetObjectNInfo(ctx context.Context, bucket, object string, r err := l.GetObject(ctx, bucket, object, startOffset, length, pw, objInfo.ETag, minio.ObjectOptions{}) pw.CloseWithError(err) }() - return minio.NewGetObjectReaderFromReader(pr, objInfo), nil + // Setup cleanup function to cause the above go-routine to + // exit in case of partial read + pipeCloser := func() { pr.Close() } + return minio.NewGetObjectReaderFromReader(pr, objInfo, pipeCloser), nil } // GetObject reads an object from B2. Supports additional diff --git a/cmd/gateway/gcs/gateway-gcs.go b/cmd/gateway/gcs/gateway-gcs.go index 7c95b65b8..88ffccb52 100644 --- a/cmd/gateway/gcs/gateway-gcs.go +++ b/cmd/gateway/gcs/gateway-gcs.go @@ -755,7 +755,10 @@ func (l *gcsGateway) GetObjectNInfo(ctx context.Context, bucket, object string, err := l.GetObject(ctx, bucket, object, startOffset, length, pw, objInfo.ETag, minio.ObjectOptions{}) pw.CloseWithError(err) }() - return minio.NewGetObjectReaderFromReader(pr, objInfo), nil + // Setup cleanup function to cause the above go-routine to + // exit in case of partial read + pipeCloser := func() { pr.Close() } + return minio.NewGetObjectReaderFromReader(pr, objInfo, pipeCloser), nil } // GetObject - reads an object from GCS. Supports additional diff --git a/cmd/gateway/manta/gateway-manta.go b/cmd/gateway/manta/gateway-manta.go index 90fbf51c7..f168dbad6 100644 --- a/cmd/gateway/manta/gateway-manta.go +++ b/cmd/gateway/manta/gateway-manta.go @@ -525,7 +525,10 @@ func (t *tritonObjects) GetObjectNInfo(ctx context.Context, bucket, object strin err := t.GetObject(ctx, bucket, object, startOffset, length, pw, objInfo.ETag, minio.ObjectOptions{}) pw.CloseWithError(err) }() - return minio.NewGetObjectReaderFromReader(pr, objInfo), nil + // Setup cleanup function to cause the above go-routine to + // exit in case of partial read + pipeCloser := func() { pr.Close() } + return minio.NewGetObjectReaderFromReader(pr, objInfo, pipeCloser), nil } // GetObject - Reads an object from Manta. Supports additional parameters like diff --git a/cmd/gateway/oss/gateway-oss.go b/cmd/gateway/oss/gateway-oss.go index 90234a130..fcf0f8c56 100644 --- a/cmd/gateway/oss/gateway-oss.go +++ b/cmd/gateway/oss/gateway-oss.go @@ -565,7 +565,10 @@ func (l *ossObjects) GetObjectNInfo(ctx context.Context, bucket, object string, err := l.GetObject(ctx, bucket, object, startOffset, length, pw, objInfo.ETag, minio.ObjectOptions{}) pw.CloseWithError(err) }() - return minio.NewGetObjectReaderFromReader(pr, objInfo), nil + // Setup cleanup function to cause the above go-routine to + // exit in case of partial read + pipeCloser := func() { pr.Close() } + return minio.NewGetObjectReaderFromReader(pr, objInfo, pipeCloser), nil } // GetObject reads an object on OSS. Supports additional diff --git a/cmd/gateway/s3/gateway-s3.go b/cmd/gateway/s3/gateway-s3.go index e90b1db71..095056d5a 100644 --- a/cmd/gateway/s3/gateway-s3.go +++ b/cmd/gateway/s3/gateway-s3.go @@ -346,7 +346,10 @@ func (l *s3Objects) GetObjectNInfo(ctx context.Context, bucket, object string, r err := l.GetObject(ctx, bucket, object, startOffset, length, pw, objInfo.ETag, minio.ObjectOptions{}) pw.CloseWithError(err) }() - return minio.NewGetObjectReaderFromReader(pr, objInfo), nil + // Setup cleanup function to cause the above go-routine to + // exit in case of partial read + pipeCloser := func() { pr.Close() } + return minio.NewGetObjectReaderFromReader(pr, objInfo, pipeCloser), nil } // GetObject reads an object from S3. Supports additional diff --git a/cmd/gateway/sia/gateway-sia.go b/cmd/gateway/sia/gateway-sia.go index e3b137d47..837736685 100644 --- a/cmd/gateway/sia/gateway-sia.go +++ b/cmd/gateway/sia/gateway-sia.go @@ -450,7 +450,10 @@ func (s *siaObjects) GetObjectNInfo(ctx context.Context, bucket, object string, err := s.GetObject(ctx, bucket, object, startOffset, length, pw, objInfo.ETag, minio.ObjectOptions{}) pw.CloseWithError(err) }() - return minio.NewGetObjectReaderFromReader(pr, objInfo), nil + // Setup cleanup function to cause the above go-routine to + // exit in case of partial read + pipeCloser := func() { pr.Close() } + return minio.NewGetObjectReaderFromReader(pr, objInfo, pipeCloser), nil } func (s *siaObjects) GetObject(ctx context.Context, bucket string, object string, startOffset int64, length int64, writer io.Writer, etag string, opts minio.ObjectOptions) error { diff --git a/cmd/xl-v1-object.go b/cmd/xl-v1-object.go index 54a123dc4..210cae428 100644 --- a/cmd/xl-v1-object.go +++ b/cmd/xl-v1-object.go @@ -211,8 +211,11 @@ func (xl xlObjects) GetObjectNInfo(ctx context.Context, bucket, object string, r err := xl.getObject(ctx, bucket, object, off, length, pw, "", ObjectOptions{}) pw.CloseWithError(err) }() + // Cleanup function to cause the go routine above to exit, in + // case of incomplete read. + pipeCloser := func() { pr.Close() } - return fn(pr, h) + return fn(pr, h, pipeCloser) } // GetObject - reads an object erasured coded across multiple