Skip to content
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

Clean up registry lock file after parse failure #2175

Merged
merged 2 commits into from
Nov 6, 2017

Conversation

HebaruSan
Copy link
Member

I have an old KSP 0.90 install that has a corrupted registry.json file (truncated in the middle of a string in the section about the installed files). If I try to access this instance with RegistryManager.Instance(), an appropriate JsonReaderException is thrown in the constructor of RegistryManager and no access is possible, but the registry.locked file is still in the folder (it is created by GetLock immediately before the parsing is attempted). Depending on exactly what the process does after that, additional exceptions can occur at random when various of the object's partially constructed resources are destroyed by the garbage collector. The lock file does disappear later when the process exits.

When a constructor throws an exception, this means the requested object cannot be created, so it should first clean up any resources it has allocated up to that point, including things like lock files, so the program is in a consistent state.

This change intercepts parsing exceptions in the constructor and calls Dispose to clean up, just like the destructor does, before re-throwing the exception. This causes the lock file to be cleaned up if the registry can't be parsed, while still alerting the calling code to the problem. It also fixes the seemingly random exceptions that I was seeing afterwards.

@HebaruSan HebaruSan added Bug Something is not working as intended Registry Issues affecting the registry labels Nov 5, 2017
@politas politas merged commit 8c3332b into KSP-CKAN:master Nov 6, 2017
@HebaruSan HebaruSan deleted the fix/dispose-on-syntax-error branch November 6, 2017 15:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something is not working as intended Registry Issues affecting the registry
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants