bullmq icon indicating copy to clipboard operation
bullmq copied to clipboard

[Bug]: Invalid environment/flags from parent cause Workers to fail when using worker_threads

Open aaronovz1 opened this issue 2 years ago • 6 comments

Version

4.3

Platform

NodeJS

What happened?

Currently when using worker_threads and supplying an unsupported flag to the parent application, workers will throw. For example, when using --max-old-space-size the worker will fail with:

[ERR_WORKER_INVALID_EXEC_ARGV]: Initiated Worker with invalid execArgv flags: --max_old_space_size=1500

How to reproduce.

No response

Relevant log output

No response

Code of Conduct

  • [X] I agree to follow this project's Code of Conduct

aaronovz1 avatar Jul 19 '23 01:07 aaronovz1

Relevant node issue https://github.com/nodejs/node/issues/41103

aaronovz1 avatar Jul 19 '23 01:07 aaronovz1

Ok. What would be the action to take from our side?

manast avatar Jul 20 '23 14:07 manast

execArgv could be filtered or allowed to be passed from the user side instead of passing in the values from the parent/main process: https://github.com/taskforcesh/bullmq/blob/59d4d1dd67a0efbab6ff252b2a042fc61c3f4df2/src/classes/child.ts#L82

I managed to figure out this very dirty workaround for now though. At the start of main() or before creating bullmq workers: process.execArgv = process.execArgv.filter((arg) => !arg.includes("--max-old-space-size="));

aaronovz1 avatar Jul 21 '23 18:07 aaronovz1

@aaronovz1 thanks for the suggested workaround.

@manast are you waiting for Node.js to fix the issue internally?

getlarge avatar Apr 03 '25 08:04 getlarge

I do not think it is BullMQ's duty to filter any invalid flags the user may pass to their child processes, as this can vary from NodeJs version and it can get really messy. On the other hand this error is detected quickly by the end user so it can be fixed without reaching production.

manast avatar Apr 03 '25 08:04 manast

I do not think it is BullMQ's duty to filter any invalid flags the user may pass to their child processes

I agree with that, however, this is not exactly the case. The situation happens here when the user is passing flags to the parent process and child workers inherit them.

On the other hand this error is detected quickly by the end user

Actually, the error is only detected once the worker is running, which is not guaranteed to happen when the application starts. This might even go undetected in e2e tests if the user don't use the unsupported flags (such as --max-old-space-size) in their e2e setup.

getlarge avatar Apr 03 '25 09:04 getlarge