Skip to content
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

Undefined concurrent writes in BuildDockerfiles #4079

Closed
mtrmac opened this issue Jun 24, 2022 · 1 comment · Fixed by #4120
Closed

Undefined concurrent writes in BuildDockerfiles #4079

mtrmac opened this issue Jun 24, 2022 · 1 comment · Fixed by #4120

Comments

@mtrmac
Copy link
Collaborator

mtrmac commented Jun 24, 2022

Steps to reproduce the issue:
Code inspection only

func BuildDockerfiles(ctx context.Context, store storage.Store, options define.BuildOptions, paths ...string) (id string, ref reference.Canonical, err error) {
defines return values id and ref, shared for the whole BuildDockerfiles function.
builds.Go(func() error {
starts a new goroutine, and that writes to id and ref at
id, ref = thisID, thisRef
without anything I can see that would prevent concurrent writes. That can have, in principle, unpredictable results (starting with getting id and ref values from different goroutines).

I suppose the idea is that on single-platform builds there is no race, and on multi-platform builds the fields are not used anyway. (Pedantically: Go is fairly imprecise about its memory model, so it’s unclear to me that “racy but unused writes” don’t trigger undefined behavior.) I can’t see that this is actually the case, nothing forces multi-platform builds to set the Manifest option which would cause id and ref to be overwritten.

Moving those writes under (renamed) instanceLock might be a one-line fix … but it seems worthwhile to move the per-platform goroutine into a completely separate function to make it impossible to similarly write to shared state without making it explicitly visible to the goroutine.

flouthoc added a commit to flouthoc/buildah that referenced this issue Jul 18, 2022
This is refactor commit which aims to remove undefined concurrent writes
from imagebuildah by making sure that fields which we are modifying are
not shared by builds for each platform so there is no undefined
concurrent write

[NO TESTS NEEDED]
[NO NEW TESTS NEEDED]
No new test is needed for this OTOH all the existing tests should pass

Closes: containers#4079

Signed-off-by: Aditya R <arajan@redhat.com>
@flouthoc
Copy link
Collaborator

I think we can avoid sharing these variable inside goroutines. Created a refactor PR above: #4120

flouthoc added a commit to flouthoc/buildah that referenced this issue Jul 18, 2022
This is refactor commit which aims to remove undefined concurrent writes
from imagebuildah by making sure that fields which we are modifying are
not shared by builds for each platform so there is no undefined
concurrent write

[NO TESTS NEEDED]
[NO NEW TESTS NEEDED]
No new test is needed for this OTOH all the existing tests should pass

Closes: containers#4079

Signed-off-by: Aditya R <arajan@redhat.com>
flouthoc added a commit to flouthoc/buildah that referenced this issue Jul 18, 2022
This is refactor commit which aims to remove undefined concurrent writes
from imagebuildah by making sure that fields which we are modifying are
not shared by builds for each platform so there is no undefined
concurrent write

[NO TESTS NEEDED]
[NO NEW TESTS NEEDED]
No new test is needed for this OTOH all the existing tests should pass

Closes: containers#4079

Signed-off-by: Aditya R <arajan@redhat.com>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 31, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants