Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

When writing session to disk, ensure we do a flush #7876

Closed
bsclifton opened this issue Mar 24, 2017 · 2 comments · Fixed by #8593
Closed

When writing session to disk, ensure we do a flush #7876

bsclifton opened this issue Mar 24, 2017 · 2 comments · Fixed by #8593

Comments

@bsclifton
Copy link
Member

per discussion with @bridiver:

We'll want to use fs.fsync when saving session-store-1 to disk. We've had problems with this file being corrupted when a BSOD happens on Windows. The save that happens every 5 mins may not have been flushed.

Notes from the discussion:

  • I think you have to use the low-level writeStream methods
  • even writeSync doesn’t force a sync to disk
  • the sequence should be create -> flush -> rename. The atomicity of rename on windows is questionable because of the method that node uses so we might want to consider patching it to use the documented atomic method
  • node rename is definitely not atomic on windows and requires a second flush because it doesn’t use the MOVEFILE_WRITE_THROUGH flag
  • create -> flush -> rename -> flush and then the file is guaranteed to be written to disk
@bsclifton bsclifton added the bug label Mar 24, 2017
@bsclifton bsclifton added this to the 0.14.1 milestone Mar 24, 2017
@bsclifton bsclifton modified the milestones: 0.14.3, 0.14.2 Apr 4, 2017
@bsclifton
Copy link
Member Author

We can use this API for doing the write:
brave/muon@2da2701

@bridiver
Copy link
Collaborator

muon.file.writeImportant(path, contents, cb(success))
The api handles serializing the saves on a per-filename basis and also blocks app.quit until the save is completed. No extra code to queue/block simultaneous writes is required and all writes happen on a separate thread.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants