Skip to content
This repository has been archived by the owner on Sep 9, 2020. It is now read-only.

Try to fix stale lock file problems mentioned in bug #820. #852

Closed
wants to merge 1 commit into from

Conversation

matjam
Copy link
Contributor

@matjam matjam commented Jul 19, 2017

What does this do / why do we need it?

This addresses the case where there is a stale lock file, or if there is multiple dep instances running. Each subsequent dep instance will now wait until the previous dep instances finish. The lock file will be removed if it is stale; it keeps track of which PIDs are active, and checks to see if the pid exists if it's busy.

It also should give better error messages if there is a problem.

What should your reviewer look out for in this PR?

Anything disastrous?

Do you need help or clarification on anything?

Which issue(s) does this PR fix?

fixes #820

@matjam
Copy link
Contributor Author

matjam commented Jul 19, 2017

Uh, I don't know how to add stuff into vendor/ in the project. git submodules? uh ..

This is embarrassing. @sdboyer :-(

return nil, CouldNotCreateLockError{
Path: glpath,
Err: fmt.Errorf("cache lock file %s exists - another process crashed or is still running?", glpath),
Err: fmt.Errorf("Unable to create lock %s: %s", glpath, err.Error()),
Copy link
Collaborator

@ibrasho ibrasho Jul 19, 2017

Choose a reason for hiding this comment

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

Start the error with a small case letter.

@matjam
Copy link
Contributor Author

matjam commented Jul 19, 2017

I've created a new PR to add the required vendor package and to fix the nits.

@matjam matjam closed this Jul 19, 2017
_, err = os.Stat(glpath)
if err == nil {
lockfile, err := lockfile.New(glpath)
if err != nil {
return nil, CouldNotCreateLockError{
Copy link
Collaborator

Choose a reason for hiding this comment

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

Slightly related to this PR: why do we define CouldNotCreateLockError as a struct, with Path when it's always included in Err?

I recommend we update CouldNotCreateLockError.Error() to allow:

return nil, CouldNotCreateLockError{
    Path: glpath,
    Err:  err,
}

by doing the following:

func (e CouldNotCreateLockError) Error() string {
	fmt.Errorf("unable to create lock %s: %s", glpath, err)
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ugly user presentation when sm.lock exists due to abort
3 participants