-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
fix(remix-node): use atomic writes for file storage #4604
Conversation
🦋 Changeset detectedLatest commit: 4d53d2e The changes in this PR will be included in the next version bump. This PR includes changesets to release 18 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Hi @midgleyc, Welcome, and thank you for contributing to Remix! Before we consider your pull request, we ask that you sign our Contributor License Agreement (CLA). We require this only once. You may review the CLA and sign it by adding your name to contributors.yml. Once the CLA is signed, the If you have already signed the CLA and received this response in error, or if you have any questions, please contact us at [email protected]. Thanks! - The Remix team |
bd7b454
to
a834812
Compare
Thank you for signing the Contributor License Agreement. Let's get this merged! 🥳 |
Hi @midgleyc and thank you so much for tackling this. |
84f481c
to
fd8ad76
Compare
fd8ad76
to
a80b73f
Compare
I've made a change to revert the initial creation back to using As the |
Hi @midgleyc! Are you still interested in getting this one merged? If so, please rebase onto latest |
All loaders run in parallel. If multiple loaders that run access the session, there is a potential race condition without atomic file writes: * Loader 1 begins overwriting the file, but does not finish * Loader 2 reads the whole file into a variable * Loader 2 attempts to parse the variable as JSON, but fails because the file was only partially written
It is only written if the file does not exist due to the 'wx' flag.
02d29f8
to
4d53d2e
Compare
Sure, I've rebased. |
hello, I am facing same problem. This PR uses write-file-atomic package to implement atomic write.
more specifically about second concern, write-file-atomic decide temporary filename as follows.
arguments for hash is filename, pid and invocations but in HA configuration, thay can be the same over instances. |
The error from the integration tests is:
This comes from esbuild, and relates to trying to bundle a (series of) packages with top level await somewhere: evanw/esbuild#253 (comment)
The integration tests have this import the I don't know what JSPM is used for, but the readme mentions "implementing the optimized browser versions of the Node.js builtins", and I think the actual node version does not contain the top level await issue. |
The current remix v1 design of parallel loader execution means that accessing the same sessions from different loaders is always non-deterministic if one or any of them are writing to the session. The approach now would be to use different sessions to read/write different values in loaders, or only read values from a shared session across loaders (no setting in loaders). |
All loaders run in parallel. If multiple loaders that run access the session, there is a potential race condition without atomic file writes:
session.set
)session.get
), but fails because the file was only partially writtenAs the test needs to reproduce a race condition involving multiple files, it is difficult to write. I think it should be possible with an integration test, but I will need to spend some more time to understand how it should work.
Closes: #4353
Testing Strategy:
We have the problem described in the attached ticket, and could reliably reproduce the original issue by rapidly switching between pages until it crashed. With the changed session storage, we have not seen the error and the original method to reproduce the issue does not crash.