-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
MaxListenersExceededWarning: Possible EventEmitter memory leak detected #2825
Comments
Can confirm I've run into the same and went looking to see if I was the only one, seems like a potential memory leak 👀 On |
Exactly the same issue. I have been receiving this in the last 3 months at least. I am using "@react-pdf/renderer": "^3.4.4"
|
I've noticed the same issue. I'm not sure, but suspect that it can have been introduced in the switch from One clue might be that the yoga-layout readme says that you must call 2.1.1
2.1.2
latest (3.4.4)
Update: I've created a simple example that generates 1000 pdf documents and prints memory usage: https://github.com/karlandindrakryggen/react-pdf-memory-issue. I've included printouts for different versions of @react-pdf/renderer in the README. |
We have the same issue at the nodejs (express) environment.
|
HI are you able to trace anything we are facing same issue when we are generating PDF more then 2000 pages. |
Hi! No, unfortunately I have not looked into this anymore. |
Same issue here, i'll just dump my node trace and comment so i can get an update when there's one (node:20944) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 uncaughtException listeners added to [process]. Use emitter.setMaxListeners() to increase limit
at _addListener (node:events:587:17)
at process.addListener (node:events:605:10)
at loadAssembly (C:\Users\Amin\Code\Deepsy-pdf\node_modules\yoga-layout\binaries\wasm-async-node.js:11:9)
at Object.loadYoga (C:\Users\Amin\Code\Deepsy-pdf\node_modules\yoga-layout\src\entrypoint\wasm-async-node.ts:25:29)
at _callee$ (C:\Users\Amin\Code\Deepsy-pdf\node_modules\@react-pdf\layout\lib\index.cjs:707:34)
at tryCatch (C:\Users\Amin\Code\Deepsy-pdf\node_modules\@babel\runtime\helpers\regeneratorRuntime.js:45:16)
at Generator.<anonymous> (C:\Users\Amin\Code\Deepsy-pdf\node_modules\@babel\runtime\helpers\regeneratorRuntime.js:133:17)
at Generator.next (C:\Users\Amin\Code\Deepsy-pdf\node_modules\@babel\runtime\helpers\regeneratorRuntime.js:74:21)
at asyncGeneratorStep (C:\Users\Amin\Code\Deepsy-pdf\node_modules\@babel\runtime\helpers\asyncToGenerator.js:3:17)
at _next (C:\Users\Amin\Code\Deepsy-pdf\node_modules\@babel\runtime\helpers\asyncToGenerator.js:17:9)
```
|
Hi, is there a solution for this issue? Any workaround? |
Edit : I just tested, this still causes memory leaks, please ignore. Not a solution but a temporary workaround until this is resolved, you might not like it.
Here's the code i've used in a nodejs server : const pdfFolder = path.join(__dirname, 'generatedPdfs');
if (!fs.existsSync(pdfFolder)) {
fs.mkdirSync(pdfFolder);
}
// Clean folder on process startup
const cleanUpFolder = () => {
fs.readdir(pdfFolder, (err, files) => {
if (err) return console.error("Error reading directory:", err);
files.forEach(file => fs.unlinkSync(path.join(pdfFolder, file)));
});
};
cleanUpFolder();
...
// Call this to clean conditionnaly
const deleteOldFiles = () => {
fs.readdir(pdfFolder, (err, files) => {
if (err) return console.error("Error reading directory:", err);
const fileStats = files.map(file => {
const filePath = path.join(pdfFolder, file);
return { file, time: fs.statSync(filePath).mtime };
});
const oneHourAgo = new Date(Date.now() - 3600000);
fileStats.forEach(({ file, time }) => {
if (time < oneHourAgo) {
fs.unlinkSync(path.join(pdfFolder, file));
}
});
if (fileStats.length > 20) {
fileStats.sort((a, b) => a.time - b.time); // TODO: Try
fileStats.slice(0, fileStats.length - 20).forEach(({ file }) => {
fs.unlinkSync(path.join(pdfFolder, file));
});
}
});
}; Also i suggest checking the filename before generating the pdf, in case you've already generated one you can directly send it. |
@jhgeluk Nevermind, looks like this is not a workaround at all ! I just did some tests in my previous code, and i still get the exact same warning, only instead of 11 emitters, it's now 15. I used both Looks like the only solution to really workaround this is to do what i've done, using babel and transforming your normal react code into a script. |
It seems that loading yoga-layout wasm binaries for each pdf is causing event emitter memory leak warning. |
@jhgeluk Sorry for the late reply, so basically i run my main server, and i have a folder with the script inside of it. And to not transform my React.jsx code into .js, i use this script here :
You'll just need to isntall : |
Describe the bug
When trying to render multiple times the same pdf with renderToBuffer() in a loop in a Nest.js app (with express), I get the following warnings in the console. Note that all the render() methods yield the same error:
If I add
process.on('warning', e => console.warn(e.stack));
to have more infos here's the results:To Reproduce
Steps to reproduce the behavior including code snippet (if applies):
npm i
&npm run start:dev
localhost:3000/api
to see the swagger-uiExpected behavior
The eventEmitters should be disposed/close correctly and there should be no warnings.
Desktop (please complete the following information):
The text was updated successfully, but these errors were encountered: