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

Lock package directory when executing Pkg commands #5628

Closed
wants to merge 1 commit into from

Conversation

jakebolewski
Copy link
Member

Possible fix for #5622. Write a simple lock file to the package directory when executing Pkg commands to prevent multiple instances of Pkg clobbering the same directory.

@jiahao
Copy link
Member

jiahao commented Jan 31, 2014

I think this could work, but one would want the ability to guard against a stale lock. (What if I ran Pkg.add and got closed my terminal window by accident, thus terminating Julia, for example...)

@jakebolewski
Copy link
Member Author

You can remove the stale lock with Pkg.rmlock() the next time you want to do anything. This is how Arch's pacman package manager does it, it seems to work well in practice.

@jiahao
Copy link
Member

jiahao commented Jan 31, 2014

True, I missed that on my first read-through. I'll shut up now.

@simonster
Copy link
Member

Not sure if it's worth putting time into this, but there are things you can do to avoid a stale lock. On *nix, Firefox uses fcntl to lock a file, or creates symlink whose target contains the pid if fcntl locking isn't supported (e.g. on old NFS) (presumably it's a symlink because creating a symlink is atomic whereas opening and writing to a file is not). If the process is killed, the fcntl lock gets released, or the symlink hopefully doesn't match a running pid. On Windows, Firefox creates a file using CreateFile with dwShareMode = 0, which has the same characteristics as fcntl-based locking. Code here.

@jakebolewski
Copy link
Member Author

@simonster that seems like quite the jump in complexity. I could work on that though it people feel it is worth it.

@simonster
Copy link
Member

Probably not worth it for now. I doubt stale locks will arise too often in practice.

@StefanKarpinski
Copy link
Member

We should really use something like flock which was designed for this and has OS support. Getting this kind of thing to actually be atomic with normal file-system operations like this is almost impossible.

@StefanKarpinski
Copy link
Member

Also has the advantage of automatically being cleaned up when a process exits.

@simonster
Copy link
Member

I think fcntl is a better approach than flock; the flock man page says it does not work under NFS but fcntl does.

@StefanKarpinski
Copy link
Member

Yeah, I don't really care which one, but we should not do this by moving files around.

@jakebolewski
Copy link
Member Author

@staticfloat brought up a good point. It would be better to hold off and leverage libgit2 for this.

@StefanKarpinski
Copy link
Member

Git will only prevent us from modifying the same git repository but there are Pkg-level operations that will stomp all over each other too. I think that we should lock on the REQUIRE file.

@staticfloat
Copy link
Member

Of course: forgot that we don't treat ~/.julia as a giant got repo anymore.
;)

Yeah, I agree. Using libuv to lock REQUIRE should work just fine.
On Jan 31, 2014 5:52 PM, "Stefan Karpinski" notifications@github.com
wrote:

Git will only prevent us from modifying the same git repository but there
are Pkg-level operations that will stomp all over each other too. I think
that we should lock on the REQUIRE file.

Reply to this email directly or view it on GitHubhttps://github.com//pull/5628#issuecomment-33859964
.

@vtjnash vtjnash added this to the 0.3 milestone Jun 16, 2014
@vtjnash
Copy link
Member

vtjnash commented Jun 16, 2014

bump. Sounds like we should lock the REQUIRE file using the system locks

@StefanKarpinski
Copy link
Member

Depends on #7176.

@JeffBezanson
Copy link
Member

This seems like a nice-to-have, but not crucial. Does it need to be in 0.3?

@JeffBezanson JeffBezanson removed this from the 0.3 milestone Jun 19, 2014
@StefanKarpinski
Copy link
Member

This definitely doesn't need to be in 0.3.

@StefanKarpinski
Copy link
Member

Why'd you close this, jake?

@jakebolewski
Copy link
Member Author

This proposed fix was wrong, old and stale. #5628 captures the underlying problem. We will have to write this functionality ourselves as libuv has decided not support any type of file locking functionality.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
packages Package management and loading
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants