-
Notifications
You must be signed in to change notification settings - Fork 110
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 bug with Lockfile
sticking around
#1341
Conversation
crates/cli/src/config.rs
Outdated
std::fs::write(&temp_path, data)?; | ||
std::fs::rename(&temp_path, file_path)?; | ||
Ok(()) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move this to the fs_utils
crate
I don't agree with removing the use of |
While this is true, I don't see any subcommands that spend a "meaningful" amount of time between reading the config and writing it; it seems unlikely that e.g. two parallel calls to Meanwhile, the If we were to address this remaining config-clobbering issue, I would actually push to just have |
} | ||
|
||
#[doc(hidden)] | ||
pub fn clone_for_test(&self) -> Self { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no longer needed since Config
is back to being "plain ol' data"
This is insufficient because the CLI may have already performed observable side-effects by the time you abort.
🤷 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I've said, I don't agree with this direction, but I'm willing to defer to you on the design here. Code is clear and does the thing it's supposed to.
I agree with this as a general point, but I didn't see any obvious commands where this seemed like an unrecoverable loss. I also didn't look very hard - Are there specific side-effects you're thinking about / know of? |
I appreciate it! But I'm pretty new here - let's get someone else to weigh in before I just override your objections. |
Coincidentally these types of problems were what databases were invented to solve. I tend to agree with Phoebe on this one, but I would also not block this merge because I think this does fix 80% of the problem. One potential way to fix the correctness issues would be to use file locks (the OS concept, not lock files) when reading and writing the file. https://chatgpt.com/share/ce2f67f5-b277-4594-8f21-6c4235f4b288 |
crates/cli/src/config.rs
Outdated
// We used to use `Lockfile` to prevent this from happening, but we had other issues with | ||
// that approach (see https://github.com/clockworklabs/SpacetimeDB/issues/1339). | ||
// We should eventually reintroduce `Lockfile`, with further fixes (see the TODO in | ||
// `lockfile.rs`). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know that we should ever reintroduce Lockfile
. I think we need a more general solution to the problem. The issue with Lockfile
is that it may never be released.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Description of Changes
Fixes #1339.
I updated
Config::save
to use an atomic write, so we no longer have the race condition that theLockfile
was originally created to address.Correspondingly, I've removed
Config
's usage ofLockfile
entirely.API and ABI breaking changes
Nope
Expected complexity level and risk
2
Testing
Describe any testing you've done, and any testing you'd like your reviewers to do,
so that you're confident that all the changes work as expected!
spacetime identity add
still works as expected