An internal filelock pkg can be found here: https://godoc.org/github.com/golang/go/src/cmd/go/internal/lockedfile/internal/filelock
A few projects are implementing file locking [1] but they do not seem to be maintained and I think they are not as nice as the internal filelock pkg I mentioned before. As a result some projects are doing their own version of it [2].
I suggest we make the filelock pkg public as I think this could be beneficial to the mass.
I'd be glad to do it given some pointers, like where to put it ?
Thanks !
[1] File lock projects:
https://github.com/gofrs/flock
https://github.com/MichaelS11/go-file-lock
https://github.com/juju/fslock
[2] Projects that implement their own file locking:
Why not use the exported version at https://godoc.org/github.com/rogpeppe/go-internal? :)
Hey @mvdan, ๐ here are a few reasons why I didn't go with it:
internal pkggo-internals to update. It sounds like it has all the annoying effects of having these pkgs not internal anyway.the filelock of go-internal is in an internal pkg
I'm not sure why that is, perhaps @rogpeppe or @myitcv can answer. Have you looked at https://godoc.org/github.com/rogpeppe/go-internal/lockedfile? That seems like a public, higher-level version of it.
That aside, sure, there are some upsides to having this in the standard library. But I think the downsides are generally greater:
cmd/go, the maintainers will probably have extra work responding to issues, reviewing patches, and fixing bugs that might not even affect cmd/goI think a far better proposal would be to include this in one of the official external repos, like x/sync. Once that's worked well for a while, then it can be part of the public standard library. This is the path that context took, for example.
lockedfile fits right to our usage and lockedfile doesn't have the filelock.ErrNotSupported. But yes lockedfile _could_ work here.
Yes, I agree this should probably be in an x/ pkg ๐, I only suggested we make the filelock pkg public and agree this would be a bit quick to put in the stdlib.
CC @bcmills
At this point we've been using lockedfile for a full release cycle and it seems mostly fine, modulo what appears to be an AIX kernel bug (#32817). I'd be fine with making it public.
Then the question is where to put it: x/sys, x/exp, x/sync, or someplace else entirely?
It's right at the intersection of sync and sys.
I _think_ lockedfile should be in x/sync/lockedfile
I _think_ that filelock is a bit lower level and could fit in x/sys/filelock ( if we ever make it public ). But these two are may be a bit redundant.
edit: regroup them both under x/exp/syssync ?
@azr, filelock should remain internal โ it's much too subtle to use on its own. (In particular, if you want your program to remain portable, you have to be very careful to stick to a narrow subset of the possible modes of use.)
If folks discover other interesting use-cases for filelock, then we can probably add more ergonomic packages to address those use-cases while still keeping filelock internal.
Given that the author of filelock says it is not ready to be exported, it seems like this is a likely decline.
Leaving open for a week for final comments.
To be clear: I support making the lockedfile package itself public โ I just want to ensure that the lockedfile/internal/filelock package remains internal to it.
I just want to ensure that the lockedfile/internal/filelock package remains internal to it.
That's fine by me ๐.
I think I'll put it in x/sync/lockedfile soonish; (unless you think another place is better ).
I misunderstood. Thanks for the clarification, @bcmills. Removing the FinalCommentPeriod label.
I don't think we are ready to add lockedfile to the standard library. It is a peculiar set of functions that does not really line up with the usual things in either os or io. Maybe it would be OK in x/sync but maybe it would be better to start in x/exp to understand if the API needs any adjustments.
If we are going to add a new public package (even in x/exp), I think the next step would be for someone to write a proper proposal doc laying out the API and explaining the decisions, get comments, and so on.
@azr, do you want to do that?
@rsc gotcha ! Yes I want to ! Where should such a proposal doc be written ? Is there a template for that ?
@azr, see https://github.com/golang/proposal#design-documents
Putting proposal on hold for design doc.
Hello there; I created the proposal ( first ever ! ) here https://github.com/golang/proposal/pull/21; I hope it's good enough please feel free to give feedback ๐ ๐ !
Change https://golang.org/cl/201277 mentions this issue: design: add proposal doc for 33974
Change https://golang.org/cl/222277 mentions this issue: cmd/go/internal/modload: use a global lockfile to avoid spurious EDEADLK on AIX and Solaris
Design doc added at https://golang.org/design/33974-add-public-lockedfile-pkg.
We also now have a solution for the AIX and Solaris EDEADLK bug pending (CL 222277). The workaround is simple (a retry loop), but the justification and regression test are at least non-trivial.
Hello @bcmills, can I already start working on this ? Can I help in any manner ? Thanks !
Most helpful comment
At this point we've been using
lockedfilefor a full release cycle and it seems mostly fine, modulo what appears to be an AIX kernel bug (#32817). I'd be fine with making it public.Then the question is where to put it:
x/sys,x/exp,x/sync, or someplace else entirely?