lksv / node-resemble.js

LOOKING FOR MAINTAINER - Image analysis and comparison
MIT License
99 stars 37 forks source link

EMFILE: too many open files when running node-resemble.js with 2 forEach loops. #39

Open bluerid opened 7 years ago

bluerid commented 7 years ago

I am getting Error: EMFILE: too many open files, open 'slices/224.png' when trying to use node-resemble.js within 2 foreach loops and comparing images from one folder to another folders. Is there a fix for the issue?

var filesArr = out.split('\n');
                    filesArr.splice(-1,1);

                    var finalArr = [];                    

                    filesArr.forEach( function(file, index) {

                      liblist.forEach(function(libFile, libIndex) {

                        var p = new Promise(( resolve ) => {
                          resemble( path.join( dirname, file ) ).compareTo( path.join( libdir, libFile ) ).ignoreColors().onComplete(function(data) {
                            if ( Number( data.misMatchPercentage ) <= 0.01 ) {
                              //console.log( data );
                              finalArr.push( libFile.charAt(0) );

                              fs.unlinkSync( path.join( dirname, file ), err => {
                                if (err) throw error;
                              });

                              if ( index === filesArr.length - 1 ) {
                                //return resolve( finalArr )
                              }

                            } else {
                              //console.log( 'No match' );
                            }
                          });
                        });

                        p.then(function(finalArr){
                          console.log(finalArr.join(""))
                          process.exit();
                        });

                      });

                    });

Complete error is...

`events.js:163
      throw er; // Unhandled 'error' event
`

If I remove the promise call then the script executes without it fine. However, for long number of characters it fails and generates the aforementioned error. pathofexilegemscom