-
Notifications
You must be signed in to change notification settings - Fork 536
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
Conversation
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). |
defers := make([]func(), 0, 2) | ||
defer func() { | ||
if err != nil { | ||
for _, f := range defers { | ||
f() | ||
} | ||
} | ||
}() |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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
Signed-off-by: Tonis Tiigi <[email protected]>
06d088e
to
19c2213
Compare
fix #3117
Avoiding creating temp dir for stdin can be done in a follow-up.