holepunchto / corestore

A simple corestore that wraps a random-access-storage module
https://docs.holepunch.to
MIT License
73 stars 29 forks source link

MaxListenersExceededWarning at inner.on('feed', onfeed) #20

Closed DougAnderson444 closed 3 years ago

DougAnderson444 commented 3 years ago

When I create several corestore namespaces using corestore.namespace(NAMESPACE), I am getting this warning on this line:

https://github.com/andrewosh/corestore/blob/bc35c5126eb9495e0d828d2bf365d41feb026bfd/index.js#L324

MaxListenersExceededWarning
Possible EventEmitter memory leak detected. 11 feed listeners added to [InnerCorestore]. 

It appears that 'feed' may only be emitted once, here?

https://github.com/andrewosh/corestore/blob/bc35c5126eb9495e0d828d2bf365d41feb026bfd/index.js#L240-L243

If this is true, and emit 'feed' is no longer needed after onready, would it make sense to either add a removeListener after onready, or use once ?

this.inner.once('feed', onfeed) 

For your consideration.

andrewosh commented 3 years ago

Hey @DougAnderson444, as mentioned in #21 I don't believe this actually represents an emitter leak, because when the namespaced corestores are closed, the listeners are removed. As for the feed event, it's currently emitted once per-core, the first time that core is loaded.

As for the feed event only being emitted once: that onready function you referenced is being registered on Hypercores, so while it's true that the feed event is emitted once per core, it's definitely emitted more than once per InnerCorestore.

Sorry for the confusion there! The MaxListenersExceededWarning definitely shouldn't be appearing, so I'll bump max listeners on the InnerCorestore to suppress it.

andrewosh commented 3 years ago

Fixed in 5.8.1