Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[fix] Bree doesn't gracefully exit #242

Copy link
Copy link

Description

@ThisIsMissEm
Issue body actions

Describe the bug

Node.js version: 20

OS version: n/a — happens on both mac and linux

Description:

When the main Bree process is terminated with ctrl+c (SIGINT), using graceful, the worker process is told to terminate, which results in it exiting with a 1 exit code, even though it was terminated by the main process.

This results in the errorHandler option receiving a Worker for job "BackgroundJob" exited with code 1 message

Actual behavior

The logs printed during graceful termination look like the following (here I'm using pino with pino-pretty as the logger:

[22:44:47.504] INFO (BackgroundJob/71797): Received cancellation of job
[22:44:47.507] INFO (71797): Worker for job "BackgroundJob" sent a message
[22:44:47.507] INFO (71797): Gracefully cancelled worker for job "BackgroundJob"
[22:44:47.519] ERROR (71797): Worker for job "BackgroundJob" exited with code 1
    err: {
      "type": "Error",
      "message": "Worker for job \"BackgroundJob\" exited with code 1",
      "stack":
          Error: Worker for job "BackgroundJob" exited with code 1
              at Worker.<anonymous> (node_modules/bree/src/index.js:476:13)
              at Worker.emit (node:events:530:35)
              at [kOnExit] (node:internal/worker:315:10)
              at Worker.<computed>.onexit (node:internal/worker:229:20)
    }
[22:44:47.524] INFO (71797): Gracefully exited

Expected behavior

Bree should be aware that it requested the job to terminate, and therefore not treat this exit code of 1 as an error, i.e., it should actually gracefully shut down.

Per the node.js Worker documentation:

The 'exit' event is emitted once the worker has stopped. If the worker exited by calling process.exit(), the exitCode parameter is the passed exit code. If the worker was terminated, the exitCode parameter is 1.

Code to reproduce

// set up logging
const logger = pino({});

// set up jobs/scheduler
// configuration in src/jobs folder
const bree = new Bree({
  logger,
  root: path.join(__dirname, "../src/jobs"),
  jobs: [
    {
      name: "BackgroundJob", // only fires on start
    },
  ],
  errorHandler: (error) => {
    logger.error(error);
  },
});

It doesn't matter what "BackgroundJob" actually does.

Checklist

  • I have searched through GitHub issues for similar issues.
  • I have completely read through the README and documentation.
  • I have tested my code with the latest version of Node.js and this package and confirmed it is still not working.
Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.