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

Recover gracefully from corrupted cache situations #71

Closed
tibirna opened this issue May 25, 2019 · 2 comments · Fixed by #103
Closed

Recover gracefully from corrupted cache situations #71

tibirna opened this issue May 25, 2019 · 2 comments · Fixed by #103
Labels
bug entry level Marks issues that can be easily addressed by new developers just starting with this project.

Comments

@tibirna
Copy link
Owner

tibirna commented May 25, 2019

If the cache file (.git/qgit_cache.dat) gets corrupted in some way (e.g. file truncated or crash in the middle of saving it), qgit can't be started anymore on the affected repository, crashing in the cache reading process.

TODO: wrap all cache process in a try...catch... and simply reconstruct cache on any error. If recovery process fails, forego use of cache and inform user for further investigation.

Related issue: #69

@tibirna tibirna added bug entry level Marks issues that can be easily addressed by new developers just starting with this project. labels May 25, 2019
@yuyichao
Copy link
Contributor

yuyichao commented Aug 31, 2020

A related issue and the root cause of the crash is that the cache loading process corrupts the memory when invalid cache is encountered and it may not be good enough to simply retry.

This happens because Cache::load stored a raw pointer from the sha buffer into the global cache (i.e. revsFiles). However, if the reads errors, the caller (Git::loadFileCache) does not keep this buffer alive so as soon as loadFileCache returns the cache is already corrupted and must not be looked at again (every keys in the hash table becomes invalid AFAICT). The solution to this problem would be to unconditionally preserve the shaBuf or revert all changes to the cache immediately.

It also seems that the reader of the shas does not check bound and simply forward the pointer by 41 bytes every cycle. A bounds check should probably be added...

yuyichao added a commit to yuyichao/qgit that referenced this issue Aug 31, 2020
Avoid corrupting memory by clearing the cache before freeing it's content.
Also adds a bounds check on the sha array.

Fix tibirna#69
Fix tibirna#71
@yuyichao
Copy link
Contributor

And just for the reference, the cause for my corrupted cache file may be openning multiple qgit on the same checkout at the same time, or using complex options to filter the commits (--not, --branches, --remotes=*, etc) or a combination of both. Clearing the cache (or let qgit do it automatically with #103) fixes the problem and trying the command line options I've used before did not reproduce it.

In this case, the fresh cache file is 4.1kB whereas the old one was 1.8MB so the currupted one is clearly not just truncated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug entry level Marks issues that can be easily addressed by new developers just starting with this project.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants