mateimarica / mateimarica.dev

Personal website with an Express.js backend.
https://mateimarica.dev
MIT License
0 stars 0 forks source link

[files] MaxListenersExceededWarning when uploading many files at once #22

Open mateimarica opened 1 year ago

mateimarica commented 1 year ago

Message when uploading many files at once (eg: 50)

MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 aborted listeners added to [IncomingMessage]. Use emitter.setMaxListeners() to increase limit

Likely caused by this block being triggered multiple times at once:

req.on('aborted', () => {
    const fullFilePath = path.join(destinationDir, fullFileName);
    file.stream.on('end', () => {
        fs.unlink(fullFilePath, (err) => {
            if (err) console.error(err);
        });
    });
    file.stream.emit('end');
});