javascript - Node.js filesystem save file error 56 EROFS while saving every 2 seconds -


i running node.js on raspbian , trying save/update file every 2/3 seconds using following code:

var savefilesaving = false;  function loop() {     mainloop = settimeout(function() {         // update data          savesavefile(data, function() {             //console.log("saved data file");             loop();         });     }, 1500); }  function savesavefile(data, callback) {     if(!savefilesaving) {         savefilesaving = true;         var wstream = fs.createwritestream(path.join(__dirname, 'save.json'));          wstream.on('finish', function () {             savefilesaving = false;             callback(data);         });          wstream.on('error', function (error) {             console.log(error);             savefilesaving = false;             wstream.end();             callback(null);         });          wstream.write(json.stringify(data));         wstream.end();     } else {         callback(null);     } } 

when run works fine hour starts spitting out:

[25/may/2016 11:3:4 am]  { [error: erofs, open '<path file>']   errno: 56,   code: 'erofs',   path: '<path file>' } 

i have tried jsonfile plugin sends out similiar write error after hour.

i have tried both filesystem.writefile , filesystem.writefilesync both give same error after hour.

i thinking had handler not being let go before new save occurs why started using savefilesaving flag.

resetting system via hard reset fixes issue (soft reset not work system seems locked up).

any suggestions guys? have searched web , found 1 other question similar 4 years ago left in limbo.

note: using callback function code continue main loop.

here ideas:

1) check free space when problem happens typing in terminal:

df -h 

2) check if file editable when problem occurs. nano or vim , etc.

3) code complicated scheduling data manipulation , writing file. because of file busy (savefilesaving) lose data until next iteration, try use code:

var    async = require('async'),   fs = require('fs'),   path = require('path');  async.forever(function(next) {   // data manipulation    try {     fs.writefilesync(path.join(__dirname, 'save.json'), json.stringify(data));   }   catch(ex) {     console.error('error writing data file:', ex);   }    settimeout(next, 2000); }); 

4) how keeping file descriptor open?

var    async = require('async'),   fs = require('fs'),   path = require('path');  var file = fs.createwritestream(path.join(__dirname, 'save.json'));  async.forever(function(next) {   // data manipulation    file.write(json.stringify(data));   settimeout(next, 2000); });  var handlesignal = function (exc) {   // close file   file.end();    if(exc) {     console.log('stopping process because of:', exc);   }   process.exit(-1); }  process.on('uncaughtexception', handlesignal); process.on('sighup', handlesignal); 

5) hardware or software problems (maybe because of os drivers) raspberry's storage controller.


Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -