Skip to content

vendor: sort imports to prevent vendoring race condition#40875

Merged
thaJeztah merged 1 commit intomoby:masterfrom
thaJeztah:sort_deps
Apr 30, 2020
Merged

vendor: sort imports to prevent vendoring race condition#40875
thaJeztah merged 1 commit intomoby:masterfrom
thaJeztah:sort_deps

Conversation

@thaJeztah
Copy link
Member

If both a "versioned" and "non-versioned" version of a dependency
exists in vendor.conf, the "longest" path should be cloned last,
otherwise the versioned dependency may be deleted when cloning its
non-versioned variant.

For example, with the following vendor.conf:

github.com/coreos/go-systemd/v22 v22.0.0
github.com/coreos/go-systemd v17

Running vndr would;

  1. recursively delete "vendor/src/github.com/coreos/go-systemd/v22:
  2. start cloning "github.com/coreos/go-systemd/v22"
  3. recursively delete "vendor/src/github.com/coreos/go-systemd"
  4. start cloning "github.com/coreos/go-systemd"

This would lead to a conflicting situation; step 3. will remove
the dependency that was previously cloned (or in the process
of being cloned).

This patch sorts the dependencies by import-path, cloning the
shortest import paths first, which should prevent the race condition.

This should address the issue seen in #40873 (comment)

If both a "versioned" and "non-versioned" version of a dependency
exists in vendor.conf, the "longest" path should be cloned last,
otherwise the versioned dependency may be deleted when cloning its
non-versioned variant.

For example, with the following vendor.conf:

github.com/coreos/go-systemd/v22 v22.0.0
github.com/coreos/go-systemd v17

Running vndr would;

1. recursively delete "vendor/src/github.com/coreos/go-systemd/v22:
2. start cloning "github.com/coreos/go-systemd/v22"
3. recursively delete "vendor/src/github.com/coreos/go-systemd"
4. start cloning "github.com/coreos/go-systemd"

This would lead to a conflicting situation; step 3. will remove
the dependency that was previously cloned (or in the process
of being cloned).

This patch sorts the dependencies by import-path, cloning the
shortest import paths first, which should prevent the race condition.

Signed-off-by: Sebastiaan van Stijn <[email protected]>
@thaJeztah
Copy link
Member Author

bringing this one in to unblock #40873

@thaJeztah thaJeztah merged commit 7e9b4c7 into moby:master Apr 30, 2020
@thaJeztah thaJeztah deleted the sort_deps branch April 30, 2020 09:37
@thaJeztah thaJeztah added this to the 20.03.0 milestone May 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants