question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

EndOfStreamException during journal recovery if journal file is zero bytes

See original GitHub issue

I 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:closed
  • Created 7 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
mbdavidcommented, Jun 7, 2017

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)

0reactions
tjmoorecommented, Jun 7, 2017

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found