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

pkg/lock: Close the file descriptor on unsuccessful locking #3616

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

shobhit85
Copy link

NewLock() opens a new file descriptor to lock on but if file
is already locked, Try*Lock() methods return error without closing
the corresponding file descriptor.

@ghost
Copy link

ghost commented Mar 14, 2017

Can one of the admins verify this patch?

@jonboulle
Copy link
Contributor

doesn't this conflict with #3615?

@shobhit85
Copy link
Author

Yes it does but created separate PR as these two PRs fix two different issues.

@lucab
Copy link
Member

lucab commented Mar 16, 2017

ok to test

@lucab
Copy link
Member

lucab commented Mar 16, 2017

I agree that NewLock should close the fd on error (good catch!). However I don't agree with other ancillary functions doing so, as it is not clear anymore who owns the fd (library or consumer) and because the operation may be re-tried on transitory errors (ENOLCK / EINTR). I would suggest instead to make explicit in costructor docstring that the consumers are responsible of calling Close on FileLock after they are done with it.

lucab
lucab previously requested changes Mar 16, 2017
return nil, err
}
// Check if the file is a regular file
if lockType == RegFile && !(stat.Mode&syscall.S_IFMT == syscall.S_IFREG) {
l.Close()
Copy link
Member

Choose a reason for hiding this comment

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

As per comment, I'd only keep these two chunks here in NewLock and adjust the docstring accordingly.

@lucab
Copy link
Member

lucab commented Mar 16, 2017

/cc @euank as he had opinions on the other similar-but-unrelated PR on the lock module.

@shobhit85
Copy link
Author

@lucab Closing fd in other ancillary functions seems necessary as caller of these functions doesn't have any handle to the fd if just err is returned. So those fds are leaked.

I'll update NewLock docstring.

@lucab
Copy link
Member

lucab commented Mar 16, 2017

@shobhit85 you are right, I got confused by those other functions acting on a *FileLock. Please disregard the first part of my comment above. Let's just tweak the docstring, and I'm ok with this.

Copy link
Member

@euank euank left a comment

Choose a reason for hiding this comment

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

Good catch; this does look like a necessary change.

The docstring improvement would also be nice of course.

Thanks!

@shobhit85
Copy link
Author

@lucab Updated the NewLock docstring. If looks good I'll go ahead and squash the commits.

@lucab
Copy link
Member

lucab commented Mar 17, 2017

@shobhit85 yes please.

NewLock() opens a new file descriptor to lock on but if file
is already locked, Try*Lock() methods return error without closing
the corresponding file descriptor.
@shobhit85
Copy link
Author

Done with rebase and squash. cc @lucab

@shobhit85
Copy link
Author

@lucab Can this be merged?

@lucab lucab closed this Oct 16, 2017
@lucab lucab reopened this Oct 16, 2017
@lucab lucab dismissed their stale review October 16, 2017 08:18

Dismissing stale review

@lucab
Copy link
Member

lucab commented Oct 16, 2017

@shobhit85 I just dismissed my stale review and re-triggered CI which was left in a confused state.

@shobhit85
Copy link
Author

@lucab That semaphoreci is still failing. Not sure why.

Copy link
Member

@iaguis iaguis 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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants