EndOfStreamException during journal recovery if journal file is zero bytes
See original GitHub issueI discovered this by (ab)using Visual Studio Stop Debugging (Shift+F5) while doing inserts and updates in a loop.
In a fairly high percentage of cases, randomly killing the process during writes leaves a journal file zero bytes long. Next time you call LiteDatabase
constructor it attempts journal recovery as usual, but fails with EndOfStreamException
.
System.IO.EndOfStreamException was unhandled
HResult=-2147024858
Message=Unable to read beyond the end of the stream.
Source=LiteDB
StackTrace:
at LiteDB.IOExceptionExtensions.WaitIfLocked(IOException ex, Int32 timer)
at LiteDB.RecoveryService.OpenExclusiveFile(String filename, Action`1 success)
at LiteDB.LiteDatabase..ctor(String connectionString)
at TestApp.Program.Main(String[] args) in c:\Users\Robin\Documents\Visual Studio 2010\Projects\TestApp\TestApp\Program.cs:line 22
For now I’m using this helper to avoid the exception:
public static void CleanupJournal()
{
var file = LiteDbName.Replace(".db", "-journal.db");
if (!File.Exists(file)) return;
var fi = new FileInfo(file);
if (fi.Length == 0) fi.Delete();
}
Issue Analytics
- State:
- Created 7 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
file content loss "Zero bytes size" on Mac OS X El Capitan
The file is displayed by the finder with "Zero bytes size" (to be correct: it should be "Zero byte size"). The file type...
Read more >How to restore perforce from version files?
I found in journal file zero bytes and remove it. On second try I get error: "Perforce server error 1 out of sequence...
Read more >0-byte file (again) - note completely destroyed
I just want to report that I just had another case of complete erasure of a note, zero byte file, all contents lost....
Read more >Recovering an accidentally deleted global
Restoring journal files in order, only globals to be restored are OK. Use ZJRNFILT only for last journal file; Export recovered global, copy...
Read more >Enabling Journaling and Creating Journal Files - InterBase
InterBase currently requires that all journal files be stored in the same directory. ... 0. PAGE SIZE. Determines the size of a journal...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @tjmoore, sorry for long time to anwser. This problem was fixed in 2.0.4 version. You can run some tests to check (this journal close mechanism was changed in v2 and v3)
Thanks. Actually just as posting I thought to simply check by creating a dummy zero length journal, and sure enough the file is removed and no crash.