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

improper locking with -w #1

Open
poeml opened this issue Jun 14, 2015 · 3 comments · May be fixed by #5
Open

improper locking with -w #1

poeml opened this issue Jun 14, 2015 · 3 comments · May be fixed by #5

Comments

@poeml
Copy link
Owner

poeml commented Jun 14, 2015

migrated from Google Code issue tracker
poeml, 2015-06-15
https://code.google.com/p/withlock/issues/detail?id=1

Reported by bmwiedemann, Feb 20, 2014
What steps will reproduce the problem?
l=test.lock ;
withlock -w100 $l "date +%s; sleep 0.3" & sleep 0.2 ;
withlock -w100 $l "date +%s; sleep 5" & sleep 0.5 ;
withlock -w100 $l "date +%s; sleep 5" ; wait

What is the expected output? What do you see instead?
expected: lock should prevent things from running at the same time.
actual: 2nd and 3rd call run in parallel

What version of the product are you using? On what operating system?
all affected (on openSUSE-12.3 among others)

Please provide any additional information below.
also filed at https://bugzilla.novell.com/show_bug.cgi?id=864785

@poeml
Copy link
Owner Author

poeml commented Jun 14, 2015

Actually fixed a year ago, just not tracked here. https://bugzilla.novell.com/show_bug.cgi?id=864785 was updated then.

So, closing!

@poeml poeml closed this as completed Jun 14, 2015
@bmwiedemann
Copy link

bug is still there

@poeml poeml reopened this Jun 18, 2015
@poeml
Copy link
Owner Author

poeml commented Jun 18, 2015

So the actual bug is the race condition between the time the lockfile is open()ed, and the lock on it is set. Especially if there is a waiting time configured, this time window is huge. Even without, the possibility for the same race condition to occur is there.

What I didn't understand at first is that this bug was blatantly covered behind the even bigger bug that the lockfile was cleanup-removed even if it was never locked by a withlock run. Okay!

I'm wondering. If the goal is to never never have two same jobs running, then the cleanup should simply not happen at all. The lockfiles should just stay in the filesystem. It doesn't harm anyone after all. Then the race condition is gone (unless a sysadmin removes the lockfile by other means.

On the other hand, if the goal is to just prevent cronjobs from stacking up, and have a "clean" filesystem, and one wants to check by lockfile-presence whether a job is running, then the cleanup should stay.

Maybe both could be possible, by configuration?

bmwiedemann added a commit to bmwiedemann/withlock that referenced this issue Jan 1, 2023
because the previous 'withlock' cleanup function might have deleted
the file and since we still held a handle to the old deleted file,
we could run concurrently with a 3rd 'withlock' which creates a new file.

Fixes poeml#1
Fixes boo#864785

Signed-off-by: Bernhard M. Wiedemann <bwiedemann@suse.de>
@bmwiedemann bmwiedemann linked a pull request Jan 1, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants