typicode / lowdb

Simple and fast JSON database
MIT License
21.54k stars 923 forks source link

Problem: Is lowdb `write()` atomic writing? #339

Closed LeaYeh closed 3 years ago

LeaYeh commented 5 years ago

I use lowdb with eletron-vue in project, and I'm confused about is write() atomic writing? Is there any risk that application crash but write() do not finish? I noticed that steno claimed in the README

Simple file writer with atomic writing and race condition prevention.
Can be used as a drop-in replacement to fs.writeFile().
Built on graceful-fs and used in lowdb.

But I got exception Malformed JSON in file when I write() DB in eletron main process and force reload read() DB in render process.

domoran commented 5 years ago

I think this is a problem with steno. It does not seem to account for multiple processes writing to a file. See this issue: https://github.com/typicode/steno/issues/10

typicode commented 3 years ago

Write is atomic but there should be only one process writing to file.