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

Bound how long to wait for lock files in FileCache. #101

Closed
wants to merge 3 commits into from

Conversation

josephw
Copy link
Contributor

@josephw josephw commented Sep 5, 2015

I was bitten by a stale lockfile in the web cache directory after stopping a prior run: by default, lockfile waits indefinitely with no diagnostics. This change adds a default timeout to cause visible failure rather than a deadlock.

As the file lock in FileCache is only held while writing a new version of the response, long waits are very likely to be due to a stale lock. Pick a reasonable default, but also allow lock_timeout
to be specified on construction.

The file lock in FileCache is only held while writing a new version of
the response. Waiting too long could be indicative of a stale lock,
so default to a reasonable timeout, but also allow 'lock_timeout'
to be specified on construction.
@ionrock
Copy link
Contributor

ionrock commented Nov 25, 2015

@josephw Sorry for a slow reply. This looks reasonable, but we need a test ensuring we're passing the timeout correctly. Basically, mocking the lock_class and ensuring the arg from the constructor gets pass through.

Thanks for the PR!

Ensure that lock_timeout defaults to a known value, which is
passed through to the lock constructor, but can be overridden
@josephw
Copy link
Contributor Author

josephw commented Nov 30, 2015

I've added a couple of tests, to make sure that a default of 30s is passed through and that a specified value is also passed through.

@josephw
Copy link
Contributor Author

josephw commented Jun 13, 2016

@ionrock ping. Is this good to merge with the added tests? Any other changes that would help?

@AndCycle
Copy link

AndCycle commented Sep 28, 2017

some extra here, as I test FileCache under windows,
the default lock_class LockFile, which use LinkLockFile internally is kind of broken under windows, as it stale while acquiring the lock,

although dir lock do works, but after further reading the lockfile package is deprecated, so we actually needs some replacement.

@zanieb
Copy link

zanieb commented Sep 14, 2022

Hi! Whatever it takes to get something like this in would be great. Happy to participate if a maintainer is interested in accepting. I just encountered this in poetry where a stale lock file got left behind and my installs just hung. It took me forever to find that the bug was an infinite timeout on an never-releasing lockfile.

@dimbleby
Copy link
Contributor

the lockfile <-> filelock switch, which is now done, was motivated by the poetry use case mentioned above. So far as poetry is concerned there is no need to put a timeout on waiting for a lock.

An MR that changes the behaviour so that a timeout is enabled by default is a breaking change: any users who are relying on the lock being an actual lock, which might be held for longer than that default timeout, would find that their code was broken.

So probably I think this MR is unnecessary - though of course there are users other than poetry - and definitely I think that changing the default behaviour is undesirable.

@zanieb
Copy link

zanieb commented May 31, 2023

@dimbleby thanks for the reply!

the lockfile <-> filelock switch, which is now done, was motivated by the poetry use case mentioned above. So far as poetry is concerned there is no need to put a timeout on waiting for a lock.

Can you link a ref for this? I don't quite follow and I guess I'm just missing some context.

An MR that changes the behaviour so that a timeout is enabled by default is a breaking change:

Definitely agree — a breaking change does not seem okay. It may be worth highlighting the current behavior and allowing a timeout to be passed still — but I'm not sure how much that applies to real use-cases.

@dimbleby
Copy link
Contributor

#284. the yanking of which is compensated for in poetry by python-poetry/poetry#6471

@josephw
Copy link
Contributor Author

josephw commented Jun 1, 2023

At least on Linux, filelock being backed by fcntl.flock means it doesn't suffer from the original problem here, because a lock won't survive its process exiting. Using a better lock is a better solution than working around it with a timeout.

@josephw josephw closed this Jun 1, 2023
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 this pull request may close these issues.

None yet

5 participants