[internal/wclayer]: fix import temp dir leak on layer extract failure#2778
Open
anmaxvl wants to merge 1 commit into
Open
[internal/wclayer]: fix import temp dir leak on layer extract failure#2778anmaxvl wants to merge 1 commit into
anmaxvl wants to merge 1 commit into
Conversation
When layer extraction fails because the disk is full, legacyLayerWriter.reset
returned early from bufWriter.Flush (ENOSPC) before closing currentFile and
backupWriter. On Windows the still-open handle prevented os.RemoveAll from
deleting the temporary import directory created by os.MkdirTemp("", "hcs"),
which by default (if not explicitly set) resolves to C:\Windows\SystemTemp\hcs*.
As a result every failed PullImage layer extract leaked an hcs* directory and
compounded disk-space exhaustion that never self-healed.
Move the handle-close logic into a deferred func in reset so the file and
backup handles are always released, even on the flush-error path, allowing the
deferred RemoveAll in legacyLayerWriterWrapper.Close to succeed. Also clean up
importPath in NewLayerWriter when newLegacyLayerWriter fails, matching
NewLayerReader's exportPath handling.
Adds wclayer reset unit tests covering the flush-error and success paths.
Co-authored-by: Claude Opus 4.8
Signed-off-by: Maksim An <maksiman@microsoft.com>
msscotb
approved these changes
Jun 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When layer extraction fails because the disk is full, legacyLayerWriter.reset returned early from bufWriter.Flush (ENOSPC) before closing currentFile and backupWriter. On Windows the still-open handle prevented os.RemoveAll from deleting the temporary import directory created by os.MkdirTemp("", "hcs"), which by default (if not explicitly set) resolves to C:\Windows\SystemTemp\hcs*. As a result every failed PullImage layer extract leaked an hcs* directory and compounded disk-space exhaustion that never self-healed.
Move the handle-close logic into a deferred func in reset so the file and backup handles are always released, even on the flush-error path, allowing the deferred RemoveAll in legacyLayerWriterWrapper.Close to succeed. Also clean up importPath in NewLayerWriter when newLegacyLayerWriter fails, matching NewLayerReader's exportPath handling.
Adds wclayer reset unit tests covering the flush-error and success paths.
Co-authored-by: Claude Opus 4.8