Skip to content

fix(sandbox): strip node --watch flags from child execArgv - #4104

Open
mohanrajvenkatesan23-04 wants to merge 3 commits into
taskforcesh:masterfrom
mohanrajvenkatesan23-04:fix/issue-1833-sandbox-watch-mode
Open

fix(sandbox): strip node --watch flags from child execArgv#4104
mohanrajvenkatesan23-04 wants to merge 3 commits into
taskforcesh:masterfrom
mohanrajvenkatesan23-04:fix/issue-1833-sandbox-watch-mode

Conversation

@mohanrajvenkatesan23-04

Copy link
Copy Markdown
Contributor

Fixes #1833

Why

When a BullMQ worker is launched with node --watch, the --watch family of flags is inherited by sandboxed child processes (and worker threads) via process.execArgv. Having the sandboxed runtime also enter watch mode interferes with the IPC channel between the parent worker and the processor:

The existing convertExecArgv filter only stripped --inspect*, so --watch and friends leaked through.

How

  • Extend convertExecArgv in src/classes/child.ts with an isWatchFlag predicate that matches --watch, --watch=*, and --watch-* and drops those entries before the existing --inspect handling.
  • Unrelated flags (including --inspect with its port-reassignment logic) are untouched.
  • Public signature of convertExecArgv is unchanged; no new exports.

Additional Notes (Optional)

  • New regression assertion in tests/child-pool.test.ts pushes the four --watch* variants (--watch, --watch-path=..., --watch-preserve-output, --watch-kill-signal=...) onto process.execArgv, asserts none end up in the forked child's spawnargs, and cleans up only the flags it added so neighbouring execArgv tests are unaffected.
  • New short "Running under node --watch" section added to docs/gitbook/guide/workers/sandboxed-processors.md warning users about custom workerForkOptions.execArgv / workerThreadsOptions.execArgv overriding the filter.

…sh#1833)

When a BullMQ worker is launched with `node --watch`, the `--watch` family
of flags is inherited by sandboxed child processes and worker threads via
`process.execArgv`. Having the sandboxed runtime also enter watch mode
interferes with the IPC channel between the parent worker and the
processor, which on older Node.js versions (<24.15) left jobs stuck in
the `active` state and on newer versions surfaced as
`ERR_WORKER_INVALID_EXEC_ARGV` crashes.

Extend `convertExecArgv` to drop any `--watch`, `--watch=*`, or
`--watch-*` entry before forwarding the remaining flags to the child.
Unrelated flags (including `--inspect` with its port-reassignment logic)
are untouched.

Adds a regression test in the child-pool suite that asserts
`--watch`, `--watch-path=...`, `--watch-preserve-output`, and
`--watch-kill-signal=...` are removed from the forked child's spawn
arguments, and documents the behaviour in the sandboxed-processors docs.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR prevents Node.js --watch* flags from leaking into BullMQ sandboxed child processes / worker threads via process.execArgv, addressing jobs getting stuck in active and newer Node versions crashing with invalid worker execArgv.

Changes:

  • Extend convertExecArgv to drop the --watch family of flags before existing --inspect* handling.
  • Add a regression test ensuring --watch* flags are not present in spawned child process arguments.
  • Document behavior and guidance when overriding execArgv via workerForkOptions / workerThreadsOptions.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/classes/child.ts Adds isWatchFlag and filters --watch* flags out of execArgv passed to children.
tests/child-pool.test.ts Adds regression coverage to ensure --watch* flags aren’t forwarded to forked children.
docs/gitbook/guide/workers/sandboxed-processors.md Documents running sandboxed processors under node --watch and warns about overrides.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/child-pool.test.ts
Address review feedback on taskforcesh#4104: when the test runner itself is started
with `node --watch`, the existing indexOf() cleanup would strip the
runner's flag. Since each watchFlag is appended via push(), lastIndexOf()
reliably targets our own entry without disturbing pre-existing values.
@mohanrajvenkatesan23-04

Copy link
Copy Markdown
Contributor Author

Thanks for the review! Pushed a follow-up addressing the cleanup concern:

  • The teardown now uses lastIndexOf instead of indexOf when removing the appended --watch* flags. Since each flag is added via push, lastIndexOf reliably targets only the entry the test added, so a pre-existing --watch* from a runner started with node --watch is left untouched.

A short comment was added so the rationale isn't lost. Happy to refactor to a snapshot/restore pattern instead if you'd prefer.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

@manast

manast commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

@copilot resolve the merge conflicts in this pull request

2 similar comments
@manast

manast commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

@copilot resolve the merge conflicts in this pull request

@manast

manast commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

@copilot resolve the merge conflicts in this pull request

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Sandboxed workers do not process jobs if running node with --watch flag

3 participants