Skip to content

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

@bluerid

Description

@bluerid

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions