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

Use lock directory to prevent race conditions #5276

Merged
merged 2 commits into from Oct 27, 2015

Conversation

mdboom
Copy link
Member

@mdboom mdboom commented Oct 19, 2015

Creation of the font cache has race conditions.

Adds a dependency on lockfile. We could vendor it if we want to, but the last thing I want to do is maintain cross-platform lockfile code...

Fix #5226.

@mdboom mdboom added this to the next bug fix release (2.0.1) milestone Oct 19, 2015
@WeatherGod
Copy link
Member

The page for the lockfile package says that the package is deprecated and
recommends using fasteners: http://fasteners.readthedocs.org/en/latest/

On Mon, Oct 19, 2015 at 11:38 AM, Michael Droettboom <
notifications@github.com> wrote:

Creation of the font cache has race conditions.

Adds a dependency on lockfile. We could vendor it if we want to, but the
last thing I want to do is maintain cross-platform lockfile code...

Fix #5226 #5226.

You can view, comment on, or merge this pull request online at:

#5276
Commit Summary

  • Use lockfile to prevent race conditions

File Changes

Patch Links:


Reply to this email directly or view it on GitHub
#5276.

@mdboom
Copy link
Member Author

mdboom commented Oct 19, 2015

Thanks for catching. What a pain, though. lockfile has been around forever and is well-tested (and actually has received updates more recently than fasteners) and does what we need and no more. fasteners has a lot more extra stuff -- but I guess if that's the future, that's where we are.

@mdboom
Copy link
Member Author

mdboom commented Oct 19, 2015

I don't think fasteners is even the appropriate tool here. It provides for thread locks or interprocess locks, but not file system locks for processes that don't even know about each other (which is our use case). I think it's odd to recommend a package that doesn't even do the same thing. I think I'd prefer to stick with filelock here.

@WeatherGod
Copy link
Member

Agreed. The alternative package that they recommend is oslo.concurrency
which seems pretty nice (has decorators and such), but I don't know if I
would have to install all of oslo to get just the concurrency part. Might
be a bit too heavy-handed for our needs. We can probably just stick with
lockfile for now, keeping our eyes open for an alternative later?

On Mon, Oct 19, 2015 at 11:57 AM, Michael Droettboom <
notifications@github.com> wrote:

I don't think fasteners is even the appropriate tool here. It provides for
thread locks or interprocess locks, but not file system locks for
processes that don't even know about each other (which is our use case). I
think it's odd to recommend a package that doesn't even do the same thing.
I think I'd prefer to stick with filelock here.


Reply to this email directly or view it on GitHub
#5276 (comment)
.

@efiring
Copy link
Member

efiring commented Oct 19, 2015

On 2015/10/19 5:57 AM, Michael Droettboom wrote:

I don't think fasteners is even the appropriate tool here. It provides
for /thread/ locks or /interprocess/ locks, but not file system locks
for processes that don't even know about each other (which is our use
case). I think it's odd to recommend a package that doesn't even do the
same thing. I think I'd prefer to stick with |filelock| here.

Looking at the documentation, I don't see how the interprocess lock is
restricted to processes that know about each other. One can use a
single decorator that takes a single path argument.

@mdboom
Copy link
Member Author

mdboom commented Oct 22, 2015

It would seem from Travis-CI that the other problem with lockfile is that it doesn't install cleanly on Python 2.x. I'll try again with fasteners.

@pelson
Copy link
Member

pelson commented Oct 22, 2015

We could vendor it if we want to, but the last thing I want to do is maintain cross-platform lockfile code...

Conda have a tried and tested lockfile implementation that we could lift... https://github.com/conda/conda/blob/master/conda/lock.py - surely this must work on all their supported platforms.

@mdboom
Copy link
Member Author

mdboom commented Oct 22, 2015

Thanks, Phil. That might work. My understanding is that the mkdir approach is the only cross-platform one (there are other, better options on *nix but those don't work on Windows).

# Keep the string "LOCKERROR" in this string so that external
# programs can look for it.
lockstr = ("""\
LOCKERROR: It looks like conda is already doing something.
Copy link
Member

Choose a reason for hiding this comment

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

Should probably change this to not say conda.

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually, I'll just take this out -- I took out the message that was displayed here anyway. I don't think the message is terribly useful in our use case.

@mdboom
Copy link
Member Author

mdboom commented Oct 27, 2015

Sorry for the quality of this PR. I was working on this between millions of test runs on another PR. I keep forgetting I'm not much of a multitasking OS...

...when creating the font cache
@mdboom
Copy link
Member Author

mdboom commented Oct 27, 2015

Ok -- I've address the comments. I also squashed the commits, because this went on a number of divergent paths to get here...

@mdboom mdboom changed the title Use lockfile to prevent race conditions Use lock directory to prevent race conditions Oct 27, 2015
@mdboom
Copy link
Member Author

mdboom commented Oct 27, 2015

I think this is good to merge. The old hacks to get around this bug have been removed, and Travis-CI is still happy.

jenshnielsen added a commit that referenced this pull request Oct 27, 2015
Use lock directory to prevent race conditions
@jenshnielsen jenshnielsen merged commit 0e6ca43 into matplotlib:master Oct 27, 2015
@jenshnielsen
Copy link
Member

Lets see how travis behaves in the long run

@timj
Copy link

timj commented Nov 9, 2015

Is this patch going to make it in to the 1.5.x release? I don't see it on that branch although I may just be looking in the wrong place.

@mdboom
Copy link
Member Author

mdboom commented Nov 9, 2015

It wasn't milestoned for that -- there's a fairly high probability for unintended consequences here. But I could be convinced otherwise if it gets enough testing.

@timj
Copy link

timj commented Nov 9, 2015

ok, we can work with the TRAVIS=1 hack in the interim.

@mdboom mdboom deleted the lockfile branch November 10, 2015 02:46
tacaswell pushed a commit that referenced this pull request Feb 8, 2016
Use lock directory to prevent race conditions

Conflicts:
    lib/matplotlib/font_manager.py
jenshnielsen added a commit to jenshnielsen/matplotlib that referenced this pull request Jul 29, 2016
This check was removed on master as a part of matplotlib#5276 which was backported

But the backport missed this line. Given that we warn about creating the cache this check is really annoying as it will show up over and over again
@jenshnielsen
Copy link
Member

Backported to 2.x as 56a932c

@QuLogic QuLogic modified the milestones: 2.0 (style change major release), 2.0.1 (next bug fix release) Jul 30, 2016
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

8 participants