My react application's production build is running in a windows server 2019, having intel Xeon 6204R CPU 4 core and 16 Gb ram. The app is working fine but if more than 20 users using the app at the same time then it is crashing with an Error-
Error: EMFILE: too many open files, open 'C:\ess\build\index.html'
Image of error I am getting while the react build crashes.
I am not able to understand if this error is because of some node limitation or on windows I have to change any setting or is it because my react code is not optimized or opening unnecessary files.
fixes I have tried-
1- created own node server to serve react build instead of serve package.
2- Monkey patching the fs module of node js with the graceful-fs module.
3- Tried to add watchman still not working.
Monkey-Patching I have done in my server.js file-
const fs = require('fs')
const gracefulFs = require('graceful-fs')
gracefulFs.gracefulify(fs);
I tried to test it with other code samples
monkey-patching for fs.readFile working fine.
for (x = 0; x < 10000; x++) {
fs.readFile('testfiles/' + x, 'utf8', (err, data) => {
data && console.log('reading file', data);
err && console.log(err?.toString());
})
}
but for fs.open still getting the same error after 8188 files.
for (x = 0; x < 10000; x++) {
fs.open('testfiles/' + x, 'rs+', function(err, fd) {
fd && console.log('reading file', fd);
if(err && i==0){
console.log('here', err?.toString());
i++;
}
});
}
Error: EMFILE: too many open files, open 'C:\ess\testfiles\8189'
I have also tried to find ulimit alternative of Linux in windows but still not able to find it.