hexojs / hexo

A fast, simple & powerful blog framework, powered by Node.js.
https://hexo.io
MIT License
39.26k stars 4.83k forks source link

Set Hexo's EventEmitter.MaxListeners to 100 #5504

Open kristofzerbe opened 3 months ago

kristofzerbe commented 3 months ago

Check List

Feature Request

I make heavy use of hexo.on("ready") and got now following NodeJS warning:

(node:16804) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 ready listeners added to [Hexo]. MaxListeners is 10. Use emitter.setMaxListeners() to increase limit

I set manually this.setMaxListeners(100); in constructor of hexo/index.js of Hexo class to avoid the problem, but it would be better to extend this in code base.

Others

No response

SukkaW commented 3 months ago

IMHO it is not common to add 11 listeners on one event. 10 looks like a sane default setting to me and I don't see any reason to increase that in Hexo.

kristofzerbe commented 3 months ago

Ok ... therefore the use of hexo.on("ready") and other events is limited in Hexo to 10, if you want to avoid those warnings. Correct? If yes, this limitation should be documented under hexo.io API

SukkaW commented 3 months ago

Ok ... therefore the use of hexo.on("ready") and other events is limited in Hexo to 10, if you want to avoid those warnings. Correct? If yes, this limitation should be documented under hexo.io API

This limitation comes from Node.js, not from Hexo.

kristofzerbe commented 3 months ago

You are right. It is a Node topic, but Hexo runs under node and has to deal with it. Maybe it could be an option to introduce a config item for this?

SukkaW commented 3 months ago

You are right. It is a Node topic, but Hexo runs under node and has to deal with it.

As I said, it is very rare to add 11 listeners on one event. In fact, in the 12 years of Hexo's history, you are the first one to see this warning.

https://github.com/hexojs/hexo/issues?q=is%3Aissue+is%3Aopen+Possible+EventEmitter+memory+leak+detected

And since you already have access to setMaxListeners, so why an extra option anyway?