-
Notifications
You must be signed in to change notification settings - Fork 65
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
refactor: Improve AuthenticationStorage #1026
Conversation
The cleanup looks good but what is the downside of keeping the lock file? It guards against multiple processes trying to access it. Maybe it doesnt happen often but I also dont see a downside it keeping it. |
@@ -91,6 +85,12 @@ impl AuthenticationStorage { | |||
self.backends.push(backend); | |||
} | |||
|
|||
/// Add a new storage backend to the authentication storage at the given index | |||
/// (backends are tried in the order they are added) | |||
pub fn insert_backend(&mut self, index: usize, backend: Arc<dyn StorageBackend + Send + Sync>) { |
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.
This will be needed for pixi's authentication-file-override
in its global config.
My suggestion would be the following order:
- file storage from $RATTLER_AUTH_FILE (if set)
- file specified in authentication-file-override in pixi global config (if set) (pixi-only that's why we need to
insert_backend(1, ...)
in pixi) - file storage from the default location
- keyring storage
- netrc storage
crates/rattler_networking/src/authentication_storage/storage.rs
Outdated
Show resolved
Hide resolved
|
||
/// Create a new authentication storage with just a file storage backend | ||
pub fn from_file(path: &std::path::Path) -> Result<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.
this was introduced in #645 but i don't think this is used anywhere so i don't think this brings us much benefit, especially now since RATTLER_AUTH_FILE
is handled directly in AuthenticationStorage::default()
it currently is not working properly 😅 |
That is expected behavior, otherwise deleting the file could create a race condition. However, instead of locking the credentials.lock file we could just lock the credentials.json itself! |
how would that work? AFAICT, |
makes sense 🤔 IMO it being irritating weighs more than potential race conditions on |
We can use an advisory lock on the file instead. |
You can use the async-fd-lock crate to achieve this locking behavior. |
thanks! 6f93e41 |
Thanks for the pointers @baszalmstra! This is ready from my side |
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.
Some final last minute small nitpitcks. We can merge after!
Thanks @pavelzw ! |
Description
While working on #1008 I noticed that
AuthenticationStorage::default()
doesn't takeRATTLER_AUTH_FILE
into account.This PR fixes this and cleans up a bit.
Also, the credentials.lock wasn't cleaned up properly and since we never concurrently write to it, I removed the lock file and made the code a bit clearer/simpler.Also, i switched the locking mechanism from creating a separate lockfile to using advisory locks on
credentials.json
.