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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

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

codecov bot commented Jan 31, 2025

Codecov Report

Attention: Patch coverage is 47.82609% with 12 lines in your changes missing coverage. Please review.

Please upload report for BASE (main@0f72b63). Learn more about missing BASE report.

Files with missing lines Patch % Lines
internal/pin/pin.go 38.46% 3 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        ?   69.26%           
=======================================
  Files           ?      105           
  Lines           ?     5446           
  Branches        ?        0           
=======================================
  Hits            ?     3772           
  Misses          ?     1231           
  Partials        ?      443           
Components Coverage Δ
Generators 47.94% <ø> (?)
Instruments ∅ <ø> (?)
Go Driver 77.58% <ø> (?)
Toolexec Driver 61.43% <ø> (?)
Aspects 78.35% <ø> (?)
Injector 76.92% <ø> (?)
Job Server 70.26% <ø> (?)
Other 69.26% <47.82%> (?)
Files with missing lines Coverage Δ
internal/filelock/filelock.go 65.51% <ø> (ø)
internal/pin/gomod.go 71.42% <60.00%> (ø)
internal/pin/pin.go 61.45% <38.46%> (ø)

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

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