Skip to content

Lock file during PATCH - #1116

Merged
kjetilk merged 7 commits into
release/v5.0.0from
feature/lock-patch
Mar 8, 2019
Merged

kjetilk merged 7 commits into
release/v5.0.0from
feature/lock-patch

Conversation

@RubenVerborgh

@RubenVerborgh RubenVerborgh commented Feb 23, 2019 •

Copy link
Copy Markdown
Contributor

Closes #1106.

This does not address other HTTP methods.

@timbl timbl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If this is using file locking, then it will need to have the lock also for PUT requests and GET requests - as a GET request could come in the middle of the patch and get a half-written file.

@RubenVerborgh

Copy link
Copy Markdown
Contributor Author

Agreed; as stated in the issue text, other methods are not done.

@kjetilk kjetilk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@megoth tested this module in a benchmark, and couldn't get it to perform reliably, so we need to be careful.

@RubenVerborgh

Copy link
Copy Markdown
Contributor Author

What benchmark, what does "reliably" mean, and compared to what?

If we are testing 100s of PATCH requests to the same file, then yes, you will see degraded performance compared to the original code. That's because the original code will happily handle two PATCH requests simultaneously and mess up the file.

The good test is 100s of PATCH requests to different files.

@kjetilk

kjetilk commented Feb 23, 2019

Copy link
Copy Markdown
Member

I'll let @megoth fill in the details, his tests are here:
https://github.com/megoth/lock-test
but the problem appeared to be that it did in fact allow overwriting the file in some cases even when the file was locked.

@RubenVerborgh

Copy link
Copy Markdown
Contributor Author

Ah the proper-lockfile module, not this PR. That seems very weird, as the library is heavily tested and widely used. Happy to use any other locking library.

@kjetilk

kjetilk commented Feb 23, 2019 •

Copy link
Copy Markdown
Member

Yeah. Pretty weird.

I might add that we reviewed like 25 different modules on npm. Most relied on a db to manage locks, mostly redis, which we found to be a too big dep to introduce. Many were mutex modules that locked the whole process rather than a file, some, like proper-lockfile and lockfile did not work as advertised...

We also went through some options with @justinwb on Friday.

Which left us with the possibility that we need to do something POSIX-specific... Anyway, you might want to talk with @megoth about it on Monday.

@RubenVerborgh

RubenVerborgh commented Feb 23, 2019 •

Copy link
Copy Markdown
Contributor Author

some, like proper-lockfile and lockfile did not work as advertised...

I'm inclined to say this is likely a test error rather than a library error, given the popularity of those libraries.

@kjetilk

kjetilk commented Feb 23, 2019

Copy link
Copy Markdown
Member

Perhaps, but I wouldn't bet on it before we have confirmed it for ourselves.

@megoth megoth left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Are we certain proper-lockfile works as intended? Is it possible to write a test for this?

Given that this works as intended, the code itself looks good (hence my Approve to this PR).

I did try to make a testsuite for locking, with the intention of being able to benchmark various solutions (https://github.com/megoth/lock-test), but I wasn't successful =/

@megoth

megoth commented Feb 28, 2019 •

Copy link
Copy Markdown
Contributor

Ok, so with #1118 rebased on this branch, and with a minor tweak to https://github.com/Inrupt-inc/generator-solid-react/tree/release/profile that enables me to spam the server with PATCH calls my findings are (drumroll) that this PR seems to be work!!! 🎉

Spamming the server also does not seem to slow down the handling of other resources noteworthy, which is also as expected with this solution.

Granted, this test is not 100% proof that this prevents data from concurrent writing , but I'm adding my approval fully behind this PR at least 😸

@RubenVerborgh

Copy link
Copy Markdown
Contributor Author

Great! Still need to address @timbl's concern of also locking other methods.

@RubenVerborgh
RubenVerborgh requested review from kjetilk and timbl March 3, 2019 14:24
@RubenVerborgh

Copy link
Copy Markdown
Contributor Author

Locking added on GET/PUT/DELETE; all good to go now.

@kjetilk kjetilk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LRGTM. The old code was rather hard to read to me, so not only seems it do what it should in terms of locking, but I think I understand it a bit better, but more reviews would certainly be appreciated.

@kjetilk

kjetilk commented Mar 3, 2019

Copy link
Copy Markdown
Member

@timbl are you good now?

@kjetilk
kjetilk merged commit 6c95b56 into release/v5.0.0 Mar 8, 2019
@kjetilk
kjetilk deleted the feature/lock-patch branch March 8, 2019 01:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants