Repository navigation
fix(stores): a corrupt state file must not stop server startup - #836
Open
TheeCoderAhmed wants to merge 1 commit into
Open
TheeCoderAhmed wants to merge 1 commit into
TheeCoderAhmed wants to merge 1 commit into
Conversation
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.
Part of #204.
Failure. Six JSON stores read their file with an unguarded
json.loadsin the constructor, andSessionManager.__init__builds them all at startup. One truncated file (a save cut off by a crash or a full disk) raises straight out of the constructor, so the server won't start until the user finds and deletes the file. To reproduce:Fix.
InboxStore,InboxRouting,UnattendedRegistry,WakeStore,SubscriptionStoreandUnroutedStorenow use the same guard asMentionSessionStore(#690): catch(OSError, ValueError, TypeError, AttributeError), log a warning, and start empty. A half-read file doesn't leave partial state behind.Left out on purpose:
PersonaConnectionStore,SessionConnectionStoreandoverrides.py. Starting empty there isn't neutral: a muted connector goes back to on, and a raised tool risk is dropped. That looks like your call, so I didn't guess.write_textin_save. It's the other half of Corrupt JSON state files crash server startup across the whole store layer (not just WakeStore/#158) #204, and I kept this PR to the load side.WakeStoreis in scope becauseselfwake.pystill has the unguarded load onmain, even though #159 was closed with "main already has the logic".Validation. New
tests/test_store_robustness.pycovers a truncated file, an empty file,null, a JSON string, and records with unknown fields.I ran those focused files with
.[dev]on Python 3.12, not the full suite. A screenshot doesn't apply: this has no UI change.