Skip to content

Add new hook dev-reload to prevent memory leaks #5132

Description

@MickL

Describe the feature

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';

export default definePlugin((nitroApp) => {
  // Starts the job runner, otherwise waiting jobs would only run after the first job is added
  useJobRunner();
});

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?

Activity

  1. added
    pending triage
    on Nov 13, 2026
  2. added theissue type on Nov 13, 2026
  3. pi0 commented on Nov 13, 2026

    @pi0
    Member

    Hi. shutdown is available in nightly sorry docs don’t have notice.

  4. MickL commented on Dec 2, 2026

    @MickL
    ContributorAuthor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    pending triage

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions