mirror of
https://github.com/minio/minio.git
synced 2025-01-11 15:03:22 -05:00
select: Fix leak on compressed files (#11302)
Properly close gzip reader when done reading fixes #11300
This commit is contained in:
parent
a5e23a40ff
commit
19fb1086b2
@ -243,6 +243,7 @@ func (api objectAPIHandlers) SelectObjectContentHandler(w http.ResponseWriter, r
|
||||
}
|
||||
return
|
||||
}
|
||||
defer s3Select.Close()
|
||||
|
||||
if err = s3Select.Open(getObject); err != nil {
|
||||
if serr, ok := err.(s3select.SelectError); ok {
|
||||
@ -281,7 +282,6 @@ func (api objectAPIHandlers) SelectObjectContentHandler(w http.ResponseWriter, r
|
||||
}
|
||||
|
||||
s3Select.Evaluate(w)
|
||||
s3Select.Close()
|
||||
|
||||
// Notify object accessed via a GET request.
|
||||
sendEvent(eventArgs{
|
||||
|
@ -57,6 +57,7 @@ type progressReader struct {
|
||||
processedReader *countUpReader
|
||||
|
||||
closedMu sync.Mutex
|
||||
gzr *gzip.Reader
|
||||
closed bool
|
||||
}
|
||||
|
||||
@ -72,15 +73,15 @@ func (pr *progressReader) Read(p []byte) (n int, err error) {
|
||||
}
|
||||
|
||||
func (pr *progressReader) Close() error {
|
||||
if pr.rc == nil {
|
||||
return nil
|
||||
}
|
||||
pr.closedMu.Lock()
|
||||
defer pr.closedMu.Unlock()
|
||||
if pr.closed {
|
||||
return nil
|
||||
}
|
||||
pr.closed = true
|
||||
if pr.gzr != nil {
|
||||
pr.gzr.Close()
|
||||
}
|
||||
return pr.rc.Close()
|
||||
}
|
||||
|
||||
@ -92,30 +93,35 @@ func (pr *progressReader) Stats() (bytesScanned, bytesProcessed int64) {
|
||||
}
|
||||
|
||||
func newProgressReader(rc io.ReadCloser, compType CompressionType) (*progressReader, error) {
|
||||
if rc == nil {
|
||||
return nil, errors.New("newProgressReader: nil reader provided")
|
||||
}
|
||||
scannedReader := newCountUpReader(rc)
|
||||
var r io.Reader
|
||||
pr := progressReader{
|
||||
rc: rc,
|
||||
scannedReader: scannedReader,
|
||||
}
|
||||
var err error
|
||||
var r io.Reader
|
||||
|
||||
switch compType {
|
||||
case noneType:
|
||||
r = scannedReader
|
||||
case gzipType:
|
||||
r, err = gzip.NewReader(scannedReader)
|
||||
pr.gzr, err = gzip.NewReader(scannedReader)
|
||||
if err != nil {
|
||||
if errors.Is(err, gzip.ErrHeader) || errors.Is(err, gzip.ErrChecksum) {
|
||||
return nil, errInvalidGZIPCompressionFormat(err)
|
||||
}
|
||||
return nil, errTruncatedInput(err)
|
||||
}
|
||||
r = pr.gzr
|
||||
case bzip2Type:
|
||||
r = bzip2.NewReader(scannedReader)
|
||||
default:
|
||||
return nil, errInvalidCompressionFormat(fmt.Errorf("unknown compression type '%v'", compType))
|
||||
}
|
||||
pr.processedReader = newCountUpReader(r)
|
||||
|
||||
return &progressReader{
|
||||
rc: rc,
|
||||
scannedReader: scannedReader,
|
||||
processedReader: newCountUpReader(r),
|
||||
}, nil
|
||||
return &pr, nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user