-
-
Notifications
You must be signed in to change notification settings - Fork 89
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
Question: Error: EMFILE: too many open files #26
Comments
walker = walk.walk("/Volumes/..");
var mm = require('music-metadata');
const util = require('util');
walker.on("file", function (root, fileStats, next) {
//todo, noch die anderen file extension freigeben
if (path.extname(fileStats.name) === ".mp3") {
next(); // Queue (asynchronous call) parsing of metadata
mm.parseFile(path.join(root, fileStats.name)).then(function (metadata) {
console.log(util.inspect(metadata, { showHidden: false, depth: null }));
next(); // asynchronous call completed, 'release' next
}).catch(function (err) {
console.error(err.message);
});
} else { // this else is required
next(); // Go to next file, no asynchronous call 'queued'
}
}); So this is I guess how to fix your existing code. var fileStats // Array of stats of directory listing.
// Take MP3 files from file listing
var mp3Stats = fileStats.filter(function () {
return path.extname(fileStats.name) === ".mp3";
});
function parseFiles (root, mp3Stats) {
var mp3Stat = mp3Stats.shift();
if (mp3Stat) {
mm.parseFile(path.join(root, mp3Stat.name)).then(function (metadata) {
console.log(util.inspect(metadata, { showHidden: false, depth: null }));
parseFiles(root, mp3Stats); // recursion
}).catch(function (err) {
console.error(err.message);
});
}
} |
Thanks for your feedback, great. For your information: My working try: if (path.extname(fileStats.name) === ".mp3") {
console.log("Mp3 found: " + path.join(root, fileStats.name));
var timer;
mm.parseFile(path.join(root, fileStats.name)).then(function (metadata) {
//console.log(util.inspect(metadata, { showHidden: false, depth: null }));
console.log("Metadaten found: next()");
next();
clearTimeout(timer);
}).catch(function (err) {
console.error(err);
console.log("Error on reading metadata: next()");
next();
clearTimeout(timer);
});
timer = setTimeout(function () {
console.log('Timeout on file: ' + path.join(root, fileStats.name));
next();
timer = null;
}, 3000);
} else {
console.log("No mp3() found");
next();
} if on Mp3 has an error it is always:
Edit: After Error 7254 files the walker loop ends and the next file to open get: EMFILE: too many open files. But there are over 80k mp3 over. without reading metatags loop works. |
Regarding first problem: After Error 7254 files the walker loop ends: I assume the too many open files are caused by massive parallel parsing of metadata. In principal the code above looks correct to me. Maybe ensure sequence by: console.log('Start parsing file: %s', fileStats.name);
mm.parseFile(path.join(root, fileStats.name)).then(function (metadata) {
//console.log(util.inspect(metadata, { showHidden: false, depth: null }));
console.log("Metadaten found: next()");
console.log('Finish parsing file: %s', fileStats.name);
next();
clearTimeout(timer);
}) Ensure output is like:
Point is, that A should finish entirely, before B is started. Regarding second problem: issue parsing for ever in corrupt MP3:
A promise should always resolve (callback in then) or reject (callback in catch). This might be a bug in the music-metadata module, if you attach this MP3 file (preferably as a new issue), I will have a look what is going on. Putting timers around this is not the way to fix it. |
Following code parsed 48k files without any issue: const walk = require('walk')
var mm = require('music-metadata');
const util = require('util');
const path = require('path');
const walker = walk.walk("M:\\");
var filesParsed = 0;
walker.on("file", function (root, fileStats, next) {
switch(path.extname(fileStats.name)) {
case ".mp3":
case ".flac":
// Queue (asynchronous call) parsing of metadata
mm.parseFile(path.join(root, fileStats.name)).then(function (metadata) {
// console.log(util.inspect(metadata, { showHidden: false, depth: null }));
console.log('Parsed %s files, last file: %s', ++filesParsed, fileStats.name);
next(); // asynchronous call completed, 'release' next
}).catch(function (err) {
console.error(err.message);
next();
});
break;
default:
next(); // Go to next file, no asynchronous call 'queued'
}
}); |
thanks for your code. I test it on an Macbook pro 8 gb Ram. Tomorrow i will test it on Windows10
can you post an email or something to send you an mp3 that failed to load |
You should have a message with my email address in your inbox. |
Version 0.8.0 works even better. if the mp3 collection is free from scrap all works fine. If not, you have an problem not the lib... Thanks for the great support! |
At first, thanks for this reader.
I want to read over 80k mp3 tags for my Software.
But after 7k the performance break down an finished with:
Error: EMFILE: too many open files....
Can someone help me to queue the async calls, with async or something like that:
https://caolan.github.io/async/docs.html#queue
Thanks
me code now is:
The text was updated successfully, but these errors were encountered: