breejs / bree

Bree is a Node.js and JavaScript job task scheduler with worker threads, cron, Date, and human syntax. Built for @ladjs, @forwardemail, @spamscanner, @cabinjs.
https://jobscheduler.net
MIT License
3.04k stars 79 forks source link

[fix] Setting job-specific worker option 'env' causes crash #171

Closed unc0ded closed 2 years ago

unc0ded commented 2 years ago

Describe the bug

Actual behavior

Setting a job-specific worker.env field to SHARE_ENV causes nodejs to crash with a DOMException [DataCloneError]: Symbol(nodejs.worker_threads.SHARE_ENV) could not be cloned.

Expected behavior

No exception should be encountered, as the worker.env field should not be cloned into the worker thread, unlike worker.workerData. The problematic piece of code can be found here at line 310, where the job object is directly added to workerData, which means that the symbol SHARE_ENV will be tried to be cloned into the worker thread, causing an exception.

Code to reproduce


jobs: [
    {
        name: 'test',
        interval: '25d',
        timeout: 0,
        worker: {
            env: SHARE_ENV
        }
    }
]

Checklist

titanism commented 2 years ago

Resolved and released the fix in v9.1.0 of Bree. Minor version bump reason is due to anyone using workerData env (which they shouldn't be); as they would typically be accessing the env from process.env. Thanks for filing this issue @unc0ded.

https://github.com/breejs/bree/releases/tag/v9.1.0