Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Worker fails to start if Node option --abort-on-uncaught-exception is set #1578

Open
mjameswh opened this issue Dec 2, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@mjameswh
Copy link
Contributor

mjameswh commented Dec 2, 2024

Describe the bug

Starting a Worker with Node option --abort-on-uncaught-exception results in the following error message:

Uncaught TypeError: Cannot read properties of undefined (reading './node_modules/@temporalio/workflow/lib/worker-interface.js')

FROM
__webpack_require__ (/srv/workflows.js:7523:55)
/srv/workflows.js:7591:13
/srv/workflows.js:7607:3
/srv/workflows.js:7610:12
Script.runInContext (node:vm:149:12)
parseWorkflowCode (/srv/node_modules/@temporalio/worker/lib/worker.js:1335:16)
Worker.getOrCreateBundle (/srv/node_modules/@temporalio/worker/lib/worker.js:331:24)
async Worker.create (/srv/node_modules/@temporalio/worker/lib/worker.js:139:24)

How to reproduce

Start the Hello World sample's Worker with:

NODE_OPTIONS=--abort-on-uncaught-exception npm run start

Details

The stack trace points out to the following code locations:

That is, while preloading the bundle code for the benefit of debuggers, the execution context isn't configured properly, so that globalThis.__webpack_module_cache__ is undefined. That causes a type error while running the bundled code, which should presumably get caught by the try-catch block in worker.ts. However, the abort-on-uncaught-exception operates at V8's level (rather than Node's event loop level) and V8's is not aware of the cross-execution-context call involved by script.runInContext(), so it can't figure out that the error happening in the child context will get properly handled by the parent context, resulting in aborting execution.

Some quick fixes are possible, e.g. adding a ?? {} suffix to the problematic line in bundler, but I'm afraid the problem may reappear at a later time as other global variables get added; we should therefore consider moving the preload to the VM.

More over, this preload somewhat expensive and only pertinent if there's an attached inspector, which is rarely the case. We should therefore make it conditional to the presence of a debugger.

@mjameswh mjameswh added the bug Something isn't working label Dec 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant