jensrossbach / node-red-contrib-chronos

Time-based Node-RED scheduling, repeating, queueing, routing, filtering and manipulating nodes
https://jensrossbach.github.io/node-red-contrib-chronos
MIT License
28 stars 1 forks source link

The flows:started event listener is not removed when the node is closed #96

Closed zachowj closed 1 year ago

zachowj commented 1 year ago

Describe the bug Was looking into the cause of the below stack trace and noticed that the flows:started listener is not getting removed on node close.

This is not the issue with the warning I am getting as I have over ten scheduler nodes in the workspace and each registers a new event listener going over the default max listener limit.

https://github.com/jensrossbach/node-red-contrib-chronos/blob/4faf519f1541667868cfb8c982e182ab41f1f47e/nodes/scheduler.js#L248

17 Sep 01:05:49 - [info] Started flows
(node:1) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 flows:started listeners added to [EventEmitter]. Use emitter.setMaxListeners() to increase limit
    at _addListener (node:events:601:17)
    at EventEmitter.addListener (node:events:619:10)
    at EventEmitter.<anonymous> (/usr/src/node-red/node_modules/@node-red/util/lib/events.js:44:33)
    at new ChronosSchedulerNode (/data/node_modules/node-red-contrib-chronos/nodes/scheduler.js:248:28)
    at Object.createNode (/usr/src/node-red/node_modules/@node-red/runtime/lib/flows/util.js:90:27)
    at Flow.start (/usr/src/node-red/node_modules/@node-red/runtime/lib/flows/Flow.js:206:48)
    at Object.start [as startFlows] (/usr/src/node-red/node_modules/@node-red/runtime/lib/flows/index.js:394:33)

To reproduce Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior A clear and concise description of what you expected to happen.

Screenshots If applicable, add screenshots to help explain your problem.

Context information Please complete the following information.

Additional information Add any other information about the problem here.

jensrossbach commented 1 year ago

Fixed with release 1.18.2.

jensrossbach commented 1 year ago

@zachowj With release 1.18.3 I did some further improvements by only registering for flows-started events if next event time option is activated (because the triggers are only needed in this case) and immediaterly unregistering the listener as soon as the event has been received.