Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repeated FAT file writes can fail after a while #1559

Closed
gfwilliams opened this issue Nov 12, 2018 · 3 comments
Closed

Repeated FAT file writes can fail after a while #1559

gfwilliams opened this issue Nov 12, 2018 · 3 comments

Comments

@gfwilliams
Copy link
Member

http://forum.espruino.com/conversations/327385/#comment14500269

var fs = require('fs');

var i = 0;
function writeData(){
  if(i++ < 1400){
   var data = Math.random().toString();
   var name = `file_${i}`;
   var res = fs.writeFile(name, data);
   if(res){
     console.log(`wrote... ${name}, ${data}`);
     setTimeout(writeData, 20);
   }
   else{
     console.log(`did not write!, ${name}, ${data}`);
   }
  }
}
i=0;writeData();

(Modified

This'll happen on linux builds if you set 'variables' : 500.

allocateJsFile fails because it can't allocate a Flat String.

Actually looking at this, it fails to make one from the freelist, runs GC, but GC doesn't free anything (despite reordering the free list) so it never tries again! Shouldn't be too hard to fix.

@gfwilliams
Copy link
Member Author

As mentioned in that post allocateJsFile should probably at the very least flip the LOW_MEMORY interpreter flag if it failed because it couldn't allocate a file

gfwilliams added a commit that referenced this issue Nov 12, 2018
@gfwilliams
Copy link
Member Author

Leaving open as perhaps we can find a way of making sure the free list stays ordered enough without GC. Also the LOW_MEMORY flag.

@gfwilliams gfwilliams changed the title Repeated file writes can fail after a while Repeated FAT file writes can fail after a while Mar 9, 2020
@gfwilliams
Copy link
Member Author

Just to add to this, there have been a bunch of recent changes to help with fragmentation and flat string allocation. The original test (under Linux with 500 vars) now works perfectly.

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

No branches or pull requests

1 participant