You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add new hook dev-reload to prevent memory leaks #5132
When starting a long-running resource in a Nitro plugin (e.g. a job queue worker like Graphite Worker), every dev reload runs the plugin again and starts another one, but there is no runtime hook to stop the previous one first, so they pile up:
(node:9212) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 gracefulShutdown listeners added to [EventEmitter]. MaxListeners is 10. Use emitter.setMaxListeners() to increase limit
Example:
import{definePlugin}from'nitro';import{useJobRunner}from'~/utils/use-job-runner';exportdefaultdefinePlugin((nitroApp)=>{// Starts the job runner, otherwise waiting jobs would only run after the first job is addeduseJobRunner();});
Btw in the docs there is a hook named 'shutdown' but it seems like it doesnt exist in latest rc.
Additional information
Would you be willing to help implement this feature?
With a new hook, #5194 would not need globalThis either. The bug had the same cause, and startScheduleRunner() could register its stop function in the hook instead of globalThis.
Activity
pi0 commentedon Nov 13, 2026
Hi. shutdown is available in nightly sorry docs don’t have notice.
MickL commentedon Dec 2, 2026
With a new hook, #5194 would not need
globalThiseither. The bug had the same cause, andstartScheduleRunner()could register its stop function in the hook instead ofglobalThis.