#528·critical

Calling `critical.generate` lots of times in parallel seems to cause MaxListenersExceededWarning

Author: gregivesCreated Mar 11, 2022Updated Oct 18, 2023

I am the author of the eleventy-critical-css Eleventy plugin which calls critical.generate for every HTML file outputted by Eleventy. An issue was filed on eleventy-critical-css saying that the plugin was causing a MaxListenersExceededWarning.

When the plugin is used with larger Eleventy sites, critical.generate is called lots of times in parallel and it causes a MaxListenersExceededWarning. Here is the stack trace:

(node:12968) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 SIGINT listeners added to [process]. Use emitter.setMaxListeners() to increase limit      
    at _addListener (events.js:475:17)
    at process.addListener (events.js:497:10)
    at module.exports (D:\Projects\critical-issue-528-reproduction\node_modules\penthouse\lib\index.js:160:11)
    at D:\Projects\critical-issue-528-reproduction\node_modules\critical\src\core.js:75:20
    at D:\Projects\critical-issue-528-reproduction\node_modules\p-all\index.js:4:67
    at D:\Projects\critical-issue-528-reproduction\node_modules\p-map\index.js:57:28

This repository was added to the issue on eleventy-critical-css which successfully reproduces the problem. If I have time, I will create a simpler reproduction, probably just by calling critical.generate lots of times in parallel. See new simpler repository below.

I am unsure if this is a problem with Critical or with Penthouse, let me know if you want me to raise an issue in the Penthouse repository instead. Thanks for your help!