-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
cmd/go/internal/modload: inconsistent locking of go.mod file #38719
Comments
@bcmills can probably correct me on this, but I believe So I guess the surprising thing to me is that From the error message, it looks like I'm not at all familiar with plan9. Is there another way we could implement advisory file locking? Barring that, we should probably use |
The |
The issue with |
The module configuration in that particular test comes from here: To me, that suggests that we should use the |
They are failing currently in master.
I agree. I'll submit a CL today. |
Fixed by CL 230838 |
In most instances where a go.mod file is read or written, it's locked using
cmd/go/internal/lockedfile
. But function(*mvsReqs).required
in modload/mvs.go just reads it usingioutil.ReadFile
. This seems a lapse from the usual discipline of locking: if a file needs protection from data races between simultaneous operations, shouldn't all accesses be performed under the same lock?In practice the inconsistent use of locking go.mod causes a problem in Plan 9, and potentially in other operating systems which have no
flock
system call. Plan 9 implementslockedfile
by settingos.modeExclusive
permissions on the file when it is first locked, and repeatedly retrying when simultaneous attempts atlockedfile.OpenFile
are excluded. This means that once a file has been locked, any subsequent simultaneous opens without usinglockedfile
will not be retried, and simply fail.This has been causing frequent failures in some of the subrepo tests, for example this one where we see this error message because go.mod is being parsed by more than one goroutine at once:
You could say that the Plan 9 implementation of
lockedfile
is the problem. Certainly its semantics is different from the linux version, but it's hard to guess fromgo doc
whether the locking is meant to be advisory or mandatory. (Or is there another specification somewhere?)My suggestion would be to use
lockedfile.Read
in place ofioutil.ReadFile
whenever parsing go.mod. But without a deep knowledge of how the module mechanism works, I can't say whether this might cause other problems. Maybe @bcmills or @rsc can advise?The text was updated successfully, but these errors were encountered: