Skip to content

Prossible perf_hooks memory leak detected #32

@Jokcy

Description

@Jokcy

It seems nanobus creates a performance entry on event emit and never clear the entry, so after a long time of using, more and more entries of performance will be in memory.

key code here:

var emitTiming = nanotiming(this._name + "('" + eventName + "')")
  var listeners = this._listeners[eventName]
  if (listeners && listeners.length > 0) {
    this._emit(this._listeners[eventName], data)
  }

  if (this._starListeners.length > 0) {
    this._emit(this._starListeners, eventName, data, emitTiming.uuid)
  }
  emitTiming()

and warning message is:

(node:84217) Warning: Possible perf_hooks memory leak detected. There are 996 entries in the Performance Timeline. Use the clear methods to remove entries that are no longer needed or set performance.maxEntries equal to a higher value (currently the maxEntries is 150).

and my test code is here:

const nanobus = require('nanobus')
const bus = nanobus()

bus.on('foo', () => {})

for (let i=0; i<1000; i++) {
  bus.emit('foo', 'bus')
}

I see this message when I use webpack-serve which use nanobus as bus to emit events.

So I guess it's a bug?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions