ngclient: Update root.json link atomically - #3010
Open
Sachith77 wants to merge 1 commit into
Open
Conversation
Removing root.json before creating the new link means a failure leaves no root.json at all, and bootstrap=None can no longer be used. Use a temp name + os.replace(), like _persist_file() does. Signed-off-by: Sachith Reddy <sachith.24bcs10403@sst.scaler.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
_update_root_symlink()deletesroot.jsonbefore creating the new link, so if the process dies in that window or the link can't be created,root.jsonjust stays gone:Since that's the trust anchor for
Updater(bootstrap=None), the client can't start after that. It also runs from afinallyblock in_load_root(), so this can happen on failure paths too.Fixed this by creating the link under a temp name and using
os.replace()to put it in place, same idea as_persist_file(). I used a fixed.tmpname instead oftempfilesinceos.symlink()needs a path that doesn't exist yet, and multiple Updater instances aren't supported anyway.Added a test that fails on develop.