Skip to content

build: make sure defers always run in the end of the build #3133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 22, 2025

Conversation

tonistiigi
Copy link
Member

fix #3117

Avoiding creating temp dir for stdin can be done in a follow-up.

@thaJeztah
Copy link
Member

Avoiding creating temp dir for stdin can be done in a follow-up.

Thanks for looking into this! Should we keep the ticket open until that part is addressed? (I haven't dug into the code yet to see where those are created; is that something I could look into? Not sure if it's complicated).

Comment on lines -208 to -215
defers := make([]func(), 0, 2)
defer func() {
if err != nil {
for _, f := range defers {
f()
}
}
}()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious if this approach (collect the release functions and a single defer would still be preferred, but possibly without the if err != nil ? I know some linters will complain about the defer release() in a loop.

build/build.go Outdated
@@ -247,7 +238,7 @@ func BuildWithResultHandler(ctx context.Context, nodes []builder.Node, opts map[
return nil, err
}
addGitAttrs(so)
defers = append(defers, release)
defer release()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be moved right before saveLocalState

@crazy-max crazy-max merged commit 9730a20 into docker:master Apr 22, 2025
138 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

build from stdin leaves behind temp-files
3 participants