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

Fix race condition when running multiple vendir from the same directory #345

Merged
merged 5 commits into from
Jan 10, 2024

Conversation

Zebradil
Copy link
Member

@Zebradil Zebradil commented Dec 26, 2023

At the moment, the temporary directory used by vendir is hardcoded to be .vendir-tmp in the current working directory.
Running multiple vendir processes in parallel will cause them to interfere with each other.

This PR is fixing the issue by creating a unique temporary directory for each vendir process.

Fixes #346

Copy link
Contributor

@100mik 100mik left a comment

Choose a reason for hiding this comment

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

The change makes sense to me!
nit: But maybe we can avoid the other lint-like changes and keep the PR concise?

@100mik
Copy link
Contributor

100mik commented Dec 27, 2023

Worth a call out, while consuming this users must ensure that there are no two vendir processes trying to write to the same path.
I am sure the way you are consuming vendir is conscious of that 🚀

@Zebradil
Copy link
Member Author

Hi @100mik, thanks for looking into this PR.

But maybe we can avoid the other lint-like changes and keep the PR concise?

Sure, done.

I am sure the way you are consuming vendir is conscious of that

Yes, destination directories are guaranteed to differ.
Before we were using --chdir flag to jump to a target directory, but that doesn't work well with directory sources that use relative paths. So we made all vendir processes run from the project root and here we are 🙂

Copy link
Contributor

@100mik 100mik left a comment

Choose a reason for hiding this comment

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

Awesome!
LGTM! But we will be needing a go ahead from one of the vendir approvers on this one
cc: @joaopapereira

Copy link
Member

@praveenrewar praveenrewar left a comment

Choose a reason for hiding this comment

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

Thank you so much for the PR @Zebradil!
I think the ask is reasonable, do you mind also opening an issue for the same?
Also, would you be able to add a test for this?

pkg/vendir/directory/staging_dir.go Show resolved Hide resolved
@Zebradil
Copy link
Member Author

Zebradil commented Dec 28, 2023

Also, would you be able to add a test for this?

I'll see what I can do. Done. At the time of filing the PR, I wanted first to make sure that the change was desirable and accepted.

UPD:

I think the ask is reasonable, do you mind also opening an issue for the same?

Will do 🙂 Done: #346

@kumaritanushree
Copy link
Contributor

LGTM

@Zebradil Zebradil requested a review from praveenrewar January 5, 2024 08:49
Copy link
Member

@praveenrewar praveenrewar left a comment

Choose a reason for hiding this comment

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

LGTM! Thank you so much for fixing the issue ❤️

pkg/vendir/directory/staging_dir.go Show resolved Hide resolved
Copy link
Member

@joaopapereira joaopapereira left a comment

Choose a reason for hiding this comment

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

I do share the concern that @100mik mentioned, but in the end, I do not think this change will make any difference.
If you fix the panic comment I think we should be in a good place to accept this PR

rootDir := ".vendir-tmp"
rootDir, err := os.MkdirTemp(".", ".vendir-tmp-")
if err != nil {
panic(fmt.Errorf("Creating tmp dir: %s", err))
Copy link
Member

Choose a reason for hiding this comment

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

Instead of panicking, let us return an error change the function signature since it is only used in 1 place in the code.

Copy link
Member Author

Choose a reason for hiding this comment

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

It calmed down 🙂

RunOpts{
Dir: tmpRoot,
StdinReader: strings.NewReader(fmt.Sprintf(yaml, n)),
AllowError: true,
Copy link
Member

Choose a reason for hiding this comment

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

nit: Since we expect this to not fail, we could set this to false.

Copy link
Member Author

Choose a reason for hiding this comment

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

True, addressed.

@Zebradil
Copy link
Member Author

Zebradil commented Jan 5, 2024

@joaopapereira

I do share the concern that @100mik mentioned, but in the end, I do not think this change will make any difference.

Did you mean this conversation?

I also think it is not ideal to create-delete-create the dir. I would remove the initial cleanup step, but I'm unsure whether it is completely safe. With the current code, where we have guarantees that the staging dir is always newly created, I don't see any risks.

Signed-off-by: German Lashevich <[email protected]>
@joaopapereira
Copy link
Member

@joaopapereira

I do share the concern that @100mik mentioned, but in the end, I do not think this change will make any difference.

Did you mean this conversation?

I also think it is not ideal to create-delete-create the dir. I would remove the initial cleanup step, but I'm unsure whether it is completely safe. With the current code, where we have guarantees that the staging dir is always newly created, I don't see any risks.

Sorry, I meant this comment:

Worth a call out, while consuming this users must ensure that there are no two vendir processes trying to write to the same path.

Copy link
Member

@joaopapereira joaopapereira left a comment

Choose a reason for hiding this comment

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

Since we are creating a new tmp folder do we need to call cleanUpAll in the Prepare function? This is going to delete the folder that we just created.

@Zebradil
Copy link
Member Author

Zebradil commented Jan 10, 2024

@joaopapereira let's remove the cleanup part then? Do you anticipate any risks in this?

UPD: I just went for it.

Copy link
Member

@joaopapereira joaopapereira left a comment

Choose a reason for hiding this comment

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

LGTM

@joaopapereira joaopapereira merged commit c1e3217 into carvel-dev:develop Jan 10, 2024
4 checks passed
@Zebradil Zebradil deleted the unique-tmp-dir branch January 10, 2024 20:20
renovate bot referenced this pull request in mykso/myks Jan 22, 2024
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [carvel.dev/vendir](https://togithub.com/carvel-dev/vendir) |
`v0.38.0` -> `v0.39.0` |
[![age](https://developer.mend.io/api/mc/badges/age/go/carvel.dev%2fvendir/v0.39.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/go/carvel.dev%2fvendir/v0.39.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/go/carvel.dev%2fvendir/v0.38.0/v0.39.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/go/carvel.dev%2fvendir/v0.38.0/v0.39.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>carvel-dev/vendir (carvel.dev/vendir)</summary>

###
[`v0.39.0`](https://togithub.com/carvel-dev/vendir/releases/tag/v0.39.0)

[Compare
Source](https://togithub.com/carvel-dev/vendir/compare/v0.38.0...v0.39.0)

<details>

<summary><h2>Installation and signature verification</h2></summary>

##### Installation
##### By downloading binary from the release

For instance, if you are using Linux on an AMD64 architecture:

```shell

### Download the binary
curl -LO https://github.com/carvel-dev/vendir/releases/download/v0.39.0/vendir-linux-amd64

### Move the binary in to your PATH
mv vendir-linux-amd64 /usr/local/bin/vendir

### Make the binary executable
chmod +x /usr/local/bin/vendir
```

##### Via Homebrew (macOS or Linux)

```shell
$ brew tap carvel-dev/carvel
$ brew install vendir
$ vendir version  
```

##### Verify checksums file signature

Install cosign on your system
https://docs.sigstore.dev/system_config/installation/

The checksums file provided within the artifacts attached to this
release is signed using
[Cosign](https://docs.sigstore.dev/cosign/overview/) with GitHub OIDC.
To validate the signature of this file, run the following commands:

```shell

### Download the checksums file, certificate and signature
curl -LO https://github.com/carvel-dev/vendir/releases/download/v0.39.0/checksums.txt
curl -LO https://github.com/carvel-dev/vendir/releases/download/v0.39.0/checksums.txt.pem
curl -LO https://github.com/carvel-dev/vendir/releases/download/v0.39.0/checksums.txt.sig

### Verify the checksums file
cosign verify-blob checksums.txt \
  --certificate checksums.txt.pem \
  --signature checksums.txt.sig \
  --certificate-identity-regexp=https://github.com/carvel-dev \
  --certificate-oidc-issuer=https://token.actions.githubusercontent.com
```

##### Verify binary integrity

To verify the integrity of the downloaded binary, you can utilize the
checksums file after having validated its signature.

```shell

### Verify the binary using the checksums file
sha256sum -c checksums.txt --ignore-missing
```

</details>

### ✨ What's new
* fix grammar in README by
@&#8203;vtrent[https://github.com/carvel-dev/vendir/pull/324](https://togithub.com/carvel-dev/vendir/pull/324)ll/324
* Added changes to sign artifacts by
@&#8203;kumaritanushr[https://github.com/carvel-dev/vendir/pull/339](https://togithub.com/carvel-dev/vendir/pull/339)ll/339
* Simplify gitignore and make sure all binaries are accounted for by
@&#8203;100m[https://github.com/carvel-dev/vendir/pull/351](https://togithub.com/carvel-dev/vendir/pull/351)ll/351
* PrivateKey with or without extra char as newline will be accepted by
@&#8203;kumaritanushr[https://github.com/carvel-dev/vendir/pull/349](https://togithub.com/carvel-dev/vendir/pull/349)ll/349
* Fix race condition when running multiple vendir from the same
directory by
@&#8203;Zebrad[https://github.com/carvel-dev/vendir/pull/345](https://togithub.com/carvel-dev/vendir/pull/345)ll/345
* Refactor lazy sync code by
@&#8203;Zebrad[https://github.com/carvel-dev/vendir/pull/340](https://togithub.com/carvel-dev/vendir/pull/340)ll/340
* Fix: updated setup cosign step in release process by
@&#8203;kumaritanushr[https://github.com/carvel-dev/vendir/pull/352](https://togithub.com/carvel-dev/vendir/pull/352)ll/352
* updated release to have installation and verification steps included
in release notes by
@&#8203;kumaritanushr[https://github.com/carvel-dev/vendir/pull/354](https://togithub.com/carvel-dev/vendir/pull/354)ll/354

#### New Contributors
* @&#8203;vtrenton made their first
contributi[https://github.com/carvel-dev/vendir/pull/324](https://togithub.com/carvel-dev/vendir/pull/324)ll/324
* @&#8203;100mik made their first
contributi[https://github.com/carvel-dev/vendir/pull/351](https://togithub.com/carvel-dev/vendir/pull/351)ll/351

**Full Changelog**:
carvel-dev/vendir@v0.38.0...v0.39.0

### 📂 Files Checksum

012531a2f1a2de8bc89f1623edfc40a7ac5aee421fe609085278fb9e287f1cdf
./vendir-linux-arm64
20b71cc25dc3fea31edf9667c92a05167f713935f854882159736443c2f7a0e6
./vendir-windows-amd64.exe
90ae82718c1072831f3097bdb031d5a897cc9f2f8334e2e1d7f35e35d0abd84f
./vendir-darwin-amd64
91ecf04ad5cdfa0f8839dc1430da7a4da665f7cb88c64c0c72202f6db261e651
./vendir-darwin-arm64
feb2836153508adfb6fd33c127e466c9ce26577678e93a252be2fec445f4501f
./vendir-linux-amd64

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log [here](https://developer.mend.io/github/mykso/myks).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4xMzUuMCIsInVwZGF0ZWRJblZlciI6IjM3LjEzNS4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
renovate bot referenced this pull request in mykso/myks Jan 22, 2024
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [carvel-dev/vendir](https://togithub.com/carvel-dev/vendir) | minor |
`v0.38.0` -> `v0.39.0` |

---

### Release Notes

<details>
<summary>carvel-dev/vendir (carvel-dev/vendir)</summary>

###
[`v0.39.0`](https://togithub.com/carvel-dev/vendir/releases/tag/v0.39.0)

[Compare
Source](https://togithub.com/carvel-dev/vendir/compare/v0.38.0...v0.39.0)

<details>

<summary><h2>Installation and signature verification</h2></summary>

##### Installation
##### By downloading binary from the release

For instance, if you are using Linux on an AMD64 architecture:

```shell

### Download the binary
curl -LO https://github.com/carvel-dev/vendir/releases/download/v0.39.0/vendir-linux-amd64

### Move the binary in to your PATH
mv vendir-linux-amd64 /usr/local/bin/vendir

### Make the binary executable
chmod +x /usr/local/bin/vendir
```

##### Via Homebrew (macOS or Linux)

```shell
$ brew tap carvel-dev/carvel
$ brew install vendir
$ vendir version  
```

##### Verify checksums file signature

Install cosign on your system
https://docs.sigstore.dev/system_config/installation/

The checksums file provided within the artifacts attached to this
release is signed using
[Cosign](https://docs.sigstore.dev/cosign/overview/) with GitHub OIDC.
To validate the signature of this file, run the following commands:

```shell

### Download the checksums file, certificate and signature
curl -LO https://github.com/carvel-dev/vendir/releases/download/v0.39.0/checksums.txt
curl -LO https://github.com/carvel-dev/vendir/releases/download/v0.39.0/checksums.txt.pem
curl -LO https://github.com/carvel-dev/vendir/releases/download/v0.39.0/checksums.txt.sig

### Verify the checksums file
cosign verify-blob checksums.txt \
  --certificate checksums.txt.pem \
  --signature checksums.txt.sig \
  --certificate-identity-regexp=https://github.com/carvel-dev \
  --certificate-oidc-issuer=https://token.actions.githubusercontent.com
```

##### Verify binary integrity

To verify the integrity of the downloaded binary, you can utilize the
checksums file after having validated its signature.

```shell

### Verify the binary using the checksums file
sha256sum -c checksums.txt --ignore-missing
```

</details>

### ✨ What's new
* fix grammar in README by
@&#8203;vtrent[https://github.com/carvel-dev/vendir/pull/324](https://togithub.com/carvel-dev/vendir/pull/324)ll/324
* Added changes to sign artifacts by
@&#8203;kumaritanushr[https://github.com/carvel-dev/vendir/pull/339](https://togithub.com/carvel-dev/vendir/pull/339)ll/339
* Simplify gitignore and make sure all binaries are accounted for by
@&#8203;100m[https://github.com/carvel-dev/vendir/pull/351](https://togithub.com/carvel-dev/vendir/pull/351)ll/351
* PrivateKey with or without extra char as newline will be accepted by
@&#8203;kumaritanushr[https://github.com/carvel-dev/vendir/pull/349](https://togithub.com/carvel-dev/vendir/pull/349)ll/349
* Fix race condition when running multiple vendir from the same
directory by
@&#8203;Zebrad[https://github.com/carvel-dev/vendir/pull/345](https://togithub.com/carvel-dev/vendir/pull/345)ll/345
* Refactor lazy sync code by
@&#8203;Zebrad[https://github.com/carvel-dev/vendir/pull/340](https://togithub.com/carvel-dev/vendir/pull/340)ll/340
* Fix: updated setup cosign step in release process by
@&#8203;kumaritanushr[https://github.com/carvel-dev/vendir/pull/352](https://togithub.com/carvel-dev/vendir/pull/352)ll/352
* updated release to have installation and verification steps included
in release notes by
@&#8203;kumaritanushr[https://github.com/carvel-dev/vendir/pull/354](https://togithub.com/carvel-dev/vendir/pull/354)ll/354

#### New Contributors
* @&#8203;vtrenton made their first
contributi[https://github.com/carvel-dev/vendir/pull/324](https://togithub.com/carvel-dev/vendir/pull/324)ll/324
* @&#8203;100mik made their first
contributi[https://github.com/carvel-dev/vendir/pull/351](https://togithub.com/carvel-dev/vendir/pull/351)ll/351

**Full Changelog**:
carvel-dev/vendir@v0.38.0...v0.39.0

### 📂 Files Checksum

012531a2f1a2de8bc89f1623edfc40a7ac5aee421fe609085278fb9e287f1cdf
./vendir-linux-arm64
20b71cc25dc3fea31edf9667c92a05167f713935f854882159736443c2f7a0e6
./vendir-windows-amd64.exe
90ae82718c1072831f3097bdb031d5a897cc9f2f8334e2e1d7f35e35d0abd84f
./vendir-darwin-amd64
91ecf04ad5cdfa0f8839dc1430da7a4da665f7cb88c64c0c72202f6db261e651
./vendir-darwin-arm64
feb2836153508adfb6fd33c127e466c9ce26577678e93a252be2fec445f4501f
./vendir-linux-amd64

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log [here](https://developer.mend.io/github/mykso/myks).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4xMzUuMCIsInVwZGF0ZWRJblZlciI6IjM3LjEzNS4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Concurrent vendir processes interfere with each other
6 participants