layer/layer_store: ensure NewInputTarStream resources are released
In applyTar, if the driver's ApplyDiff returns an error, the function
returns early without calling io.Copy.
As a consequence, the resources (a goroutine and some buffers holding
the uncompressed image, the digest, etc...) allocated or referenced by
NewInputTarStream above aren't released, as the worker goroutine only
finishes when it finds EOF or a closed pipe.
Signed-off-by: Sergio Lopez <slp@redhat.com>
(cherry picked from commit 5846db10af
)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
e4b8756784
commit
f660ef2c25
1 changed files with 4 additions and 3 deletions
|
@ -253,13 +253,14 @@ func (ls *layerStore) applyTar(tx *fileMetadataTransaction, ts io.Reader, parent
|
||||||
}
|
}
|
||||||
|
|
||||||
applySize, err := ls.driver.ApplyDiff(layer.cacheID, parent, rdr)
|
applySize, err := ls.driver.ApplyDiff(layer.cacheID, parent, rdr)
|
||||||
|
// discard trailing data but ensure metadata is picked up to reconstruct stream
|
||||||
|
// unconditionally call io.Copy here before checking err to ensure the resources
|
||||||
|
// allocated by NewInputTarStream above are always released
|
||||||
|
io.Copy(ioutil.Discard, rdr) // ignore error as reader may be closed
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Discard trailing data but ensure metadata is picked up to reconstruct stream
|
|
||||||
io.Copy(ioutil.Discard, rdr) // ignore error as reader may be closed
|
|
||||||
|
|
||||||
layer.size = applySize
|
layer.size = applySize
|
||||||
layer.diffID = DiffID(digester.Digest())
|
layer.diffID = DiffID(digester.Digest())
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue