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

Handle cross-process conflict #1

Open
jamestalmage opened this issue Nov 13, 2015 · 2 comments
Open

Handle cross-process conflict #1

jamestalmage opened this issue Nov 13, 2015 · 2 comments

Comments

@jamestalmage
Copy link

We need this to work across multiple process.

Specifically, how to handle cacha.get when the file is still open for write via cacha.set in a separate process.

I am not sure exactly how Node behaves in this scenario (hopefully it just returns / throws an error). If that's the case, maybe just a delay / retry loop.

Alternatively (but more complicated, and I'm still not 100% sure how it would look); Have it write to a temp file, then rename. I think renames are atomic cross-platform.

Windows: how to do atomic writes in a file

Things UNIX can do atomically

I think we are mostly safe on this since the file name is the hash of the contents.
That prevents us from having to decide who "wins" in a race condition for writes (if a race condition for the same filename exists, it doesn't matter who wins - they are both trying to write the same contents).

The issue is mostly how to handle reads while the file is write-locked.

@sindresorhus
Copy link

See sindresorhus/configstore#20 and how it was solved.

@jamestalmage
Copy link
Author

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

No branches or pull requests

2 participants