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: auto-pin race condition on go.mod file #521

Merged
merged 4 commits into from
Feb 11, 2025

Conversation

RomainMuller
Copy link
Contributor

@RomainMuller RomainMuller commented Jan 31, 2025

When using -toolexec mode, the auto-pin process may be initiated by multiple concurrent executions of the toolexec proxy. In such cases, there is a race condition on access to go.mod and orchestrion.tool.go, which often results in go mod tidy failing due to it detecting concurrent modifications of the go.mod (it may also result in corrupt content of the orchestrion.tool.go file).

This addresses the issue by having the auto-pin process acquire an advisory write lock on the go.mod file, making sure all attempts are properly synchronized, and only one attempt tries to modify the file at a time.

Fixes #491

When using `-toolexec` mode, the auto-pin process may be initiated by
multiple concurrent executions of the `toolexec` proxy. In such cases,
there is a race condition on access to `go.mod` and
`orchestrion.tool.go`, which often results in `go mod tidy` failing due
to it detecting concurrent modifications of the `go.mod` (it may also
result in corrupt content of the `orchestrion.tool.go` file).

This addresses the issue by having the auto-pin process acquire an
advisory write lock on the `go.mod` file, making sure all attempts are
properly synchronized, and only one attempt tries to modify the file at
a time.
@RomainMuller RomainMuller requested a review from a team as a code owner January 31, 2025 09:59
internal/pin/gomod.go Show resolved Hide resolved
internal/pin/gomod.go Show resolved Hide resolved
Copy link
Member

@kakkoyun kakkoyun left a comment

Choose a reason for hiding this comment

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

LGTM

@RomainMuller RomainMuller added this pull request to the merge queue Feb 3, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 3, 2025
…pin-race

# Conflicts:
#	internal/pin/auto_test.go
@RomainMuller RomainMuller added this pull request to the merge queue Feb 11, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 11, 2025
@RomainMuller RomainMuller added this pull request to the merge queue Feb 11, 2025
Merged via the queue into main with commit 5024673 Feb 11, 2025
45 checks passed
@RomainMuller RomainMuller deleted the romain.marcadier/autopin-race branch February 11, 2025 17:49
Copy link

codecov bot commented Feb 11, 2025

Codecov Report

Attention: Patch coverage is 44.00000% with 14 lines in your changes missing coverage. Please review.

Project coverage is 63.84%. Comparing base (020b6fe) to head (3e4df5f).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
internal/pin/pin.go 33.33% 5 Missing and 5 partials ⚠️
internal/pin/gomod.go 60.00% 1 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #521      +/-   ##
==========================================
- Coverage   67.73%   63.84%   -3.89%     
==========================================
  Files         106      106              
  Lines        6889     6899      +10     
==========================================
- Hits         4666     4405     -261     
- Misses       1744     2031     +287     
+ Partials      479      463      -16     
Components Coverage Δ
Generators 46.17% <ø> (ø)
Instruments ∅ <ø> (∅)
Go Driver 73.42% <ø> (-0.68%) ⬇️
Toolexec Driver 54.49% <ø> (-4.01%) ⬇️
Aspects 71.06% <ø> (-4.56%) ⬇️
Injector 71.81% <ø> (-3.28%) ⬇️
Job Server 65.98% <ø> (-3.50%) ⬇️
Other 63.84% <44.00%> (-3.89%) ⬇️
Files with missing lines Coverage Δ
internal/filelock/filelock.go 40.98% <ø> (ø)
internal/pin/gomod.go 65.21% <60.00%> (ø)
internal/pin/pin.go 56.03% <33.33%> (-0.73%) ⬇️

... and 28 files with indirect coverage changes

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.

go.mod changed during editing; not overwriting
2 participants