Browser-laptop: When writing session to disk, ensure we do a flush

Created on 24 Mar 2017  路  2Comments  路  Source: brave/browser-laptop

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鈥檛 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鈥檛 use the MOVEFILE_WRITE_THROUGH flag
  • create -> flush -> rename -> flush and then the file is guaranteed to be written to disk
Qtest-plan-required bug release-noteinclude

Most helpful comment

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.

All 2 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jonathansampson picture jonathansampson  路  3Comments

jonathansampson picture jonathansampson  路  3Comments

luixxiul picture luixxiul  路  3Comments

stevespringett picture stevespringett  路  3Comments

jonathansampson picture jonathansampson  路  3Comments