sdk-typescript icon indicating copy to clipboard operation
sdk-typescript copied to clipboard

[Bug] EvalError: Code generation from strings disallowed for this context

Open zomble opened this issue 5 years ago • 17 comments

Describe the bug

Workflow fails due to eval call in webpack generated code.

To Reproduce

Steps to reproduce the behaviour:

  1. Follow examples (with sourcemaps)
  2. Run a workflow.

Expected behaviour

Workflow executes.

Screenshots/Terminal output

{
  "message": "Code generation from strings disallowed for this context",
  "source": "",
  "stackTrace": "EvalError: Code generation from strings disallowed for this context\n    at Object../build/workflows sync recursive ^\\.\\/.*\\.js$ (<isolated-vm>:118:1)\n    at __webpack_require__ (<isolated-vm>:623:42)\n    at eval (webpack://lib/../../../../../../src/main.js?:11:13)\n    at eval (webpack://lib/./node_modules/@temporalio/workflow/lib/internals.js?:63:25)\n    at Activator.startWorkflow (webpack://lib/./node_modules/@temporalio/workflow/lib/internals.js?:67:9)\n    at activate (webpack://lib/./node_modules/@temporalio/workflow/lib/worker-interface.js?:128:45)",
  "cause": null,
  "applicationFailureInfo": {
    "type": "EvalError",
    "nonRetryable": false,
    "details": null
  },
  "failureInfo": "applicationFailureInfo"
}

Versions

  • OS: Linux
  • Temporal Version 1.10.0
  • Docker

Additional context

It's due to default devtool in webpack development mode, eval. Either setting the mode to production, or devtool (like "source-map") to something else not using eval corrects the issue.

zomble avatar Jun 26 '21 01:06 zomble

Hi, can you please post a sample Workflow that reproduces this behavior? We run the example in CI and I haven't seen any issues with webpack. I'll look into changing the devtool as you suggested, I just left the default webpack config because it "just worked".

bergundy avatar Jun 26 '21 16:06 bergundy

Hey, I can repro following the getting started guide.

https://docs.temporal.io/docs/node/getting-started

node lib/worker/schedule-workflow.js returns

WorkflowExecutionFailedError: Code generation from strings disallowed for this context
    at Connection.untilComplete (/home/user/temporal/example/node_modules/@temporalio/client/lib/index.js:204:19)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at async Object.start (/home/user/temporal/example/node_modules/@temporalio/client/lib/index.js:284:25)
    at async run (/home/user/temporal/example/lib/worker/schedule-workflow.js:11:20)

With this result in temporal as:

{
  "message": "Code generation from strings disallowed for this context",
  "source": "",
  "stackTrace": "EvalError: Code generation from strings disallowed for this context\n    at Object../lib/workflows sync recursive ^\\.\\/.*\\.js$ (<isolated-vm>:30:1)\n    at __webpack_require__ (<isolated-vm>:524:42)\n    at eval (webpack://lib/../../../../../src/main.js?:11:13)\n    at eval (webpack://lib/./node_modules/@temporalio/workflow/lib/internals.js?:63:25)\n    at Activator.startWorkflow (webpack://lib/./node_modules/@temporalio/workflow/lib/internals.js?:67:9)\n    at activate (webpack://lib/./node_modules/@temporalio/workflow/lib/worker-interface.js?:128:45)",
  "cause": null,
  "applicationFailureInfo": {
    "type": "EvalError",
    "nonRetryable": false,
    "details": null
  },
  "failureInfo": "applicationFailureInfo"
}

Screenshot (23)

zomble avatar Jun 28 '21 00:06 zomble

Which node version are you using? I'm trying to figure out why I can't reproduce.

bergundy avatar Jun 28 '21 00:06 bergundy

$ node --version v14.17.1

$ cat node_modules/temporalio/package.json
{
  "name": "temporalio",
  "version": "0.2.5",
  "description": "Temporal.io SDK meta-package",
  "dependencies": {
    "@temporalio/client": "^0.4.3",
    "@temporalio/proto": "^0.2.3",
    "@temporalio/worker": "^0.5.0",
    "@temporalio/workflow": "^0.4.0"
  },
  "author": "Roey Berman <[email protected]>",
  "license": "MIT",
  "repository": {
    "type": "git",
    "url": "git+https://github.com/temporalio/sdk-node.git"
  },
  "keywords": [
    "temporal",
    "workflow",
    "isolate"
  ],
  "bugs": {
    "url": "https://github.com/temporalio/sdk-node/issues"
  },
  "homepage": "https://github.com/temporalio/sdk-node#readme",
  "publishConfig": {
    "access": "public"
  },
  "engines": {
    "node": ">=14.0.0"
  },
  "gitHead": "766f94c1154962fe367f5b2d8737a50bc3badde9"
}

zomble avatar Jun 28 '21 01:06 zomble

I'll try to reproduce this when I get the chance

bergundy avatar Jun 28 '21 04:06 bergundy

I tried to reproduce but I can't. Ran with docker image amd64/node:14, followed the instructions on the getting started page and it worked. I'm using [email protected] and node v14.17.1. I'm wondering if it's an issue with cached packages since we usually test on fresh machines. Can you try to run with a different node version (using nvm for example) to make sure that you're not using any cached packages on your system? That's the best lead I have so far.

bergundy avatar Jun 28 '21 14:06 bergundy

Okay. Strange.

$ rm -Rf node_modules/
$ rm package-lock.json
$ nvm use 16
Now using node v16.3.0 (npm v7.17.0)
$ npm cache clean --force
npm WARN using --force Recommended protections disabled.
$ npm install

added 125 packages, and audited 126 packages in 20s

11 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

$ npm run build.watch
[9:32:22 am] Starting compilation in watch mode...

[9:32:22 am] Found 0 errors. Watching for file changes.

$ npm run start

> [email protected] start
> node lib/worker

2021-06-28T23:36:09.425Z [INFO] asset main.js 4.81 MiB [emitted] (name: main)
2021-06-28T23:36:09.426Z [INFO] runtime modules 1.13 KiB 5 modules
2021-06-28T23:36:09.426Z [INFO] modules by path ./node_modules/ 4.68 MiB
2021-06-28T23:36:09.426Z [INFO]   modules by path ./node_modules/@temporalio/ 4.57 MiB 21 modules
2021-06-28T23:36:09.426Z [INFO]   modules by path ./node_modules/protobufjs/ 51.2 KiB 11 modules
2021-06-28T23:36:09.426Z [INFO]   modules by path ./node_modules/@protobufjs/ 23.7 KiB 7 modules
2021-06-28T23:36:09.426Z [INFO]   ./node_modules/long/src/long.js 39.2 KiB [built] [code generated]
2021-06-28T23:36:09.426Z [INFO]   ./node_modules/ms/index.js 2.95 KiB [built] [code generated]
2021-06-28T23:36:09.426Z [INFO] modules by path ../../../../../src/ 769 bytes
2021-06-28T23:36:09.426Z [INFO]   ../../../../../src/main.js 555 bytes [built] [code generated]
2021-06-28T23:36:09.426Z [INFO]   ../../../../../src/@activities/greeter.js 214 bytes [built] [code generated]
2021-06-28T23:36:09.426Z [INFO] modules by path ./lib/workflows/ 575 bytes
2021-06-28T23:36:09.426Z [INFO]   ./lib/workflows/ sync ^\.\/.*\.js$ 177 bytes [built] [code generated]
2021-06-28T23:36:09.426Z [INFO]   ./lib/workflows/example.js 398 bytes [built] [code generated]
2021-06-28T23:36:09.426Z [INFO] webpack 5.41.0 compiled successfully in 717 ms
2021-06-28T23:36:09.659Z [INFO] Worker state changed { state: 'RUNNING' }

$ node lib/worker/schedule-workflow

WorkflowExecutionFailedError: Code generation from strings disallowed for this context
    at Connection.untilComplete (/home/user/temporal/example/node_modules/@temporalio/client/lib/index.js:204:19)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at async Object.start (/home/user/temporal/example/node_modules/@temporalio/client/lib/index.js:284:25)
    at async run (/home/user/temporal/example/lib/worker/schedule-workflow.js:11:20)

The moment I alter ./node_modules/@temporalio/worker/lib/isolate-builder.js:L123 with + devtool: 'cheap-source-map', or any devtool options that isn't eval including false, and restart the worker.

  $ node lib/worker/schedule-workflow
Hello, Temporal!

Do you get if you forcefully set the devtool to something eval based? Just wondering if webpack is selecting false for you over eval, but it shouldn't be.

zomble avatar Jun 29 '21 00:06 zomble

Could it be some environment variable that you have set? I will explicitly set the devtool so this can't happen but I want to understand why this is happening to you.

bergundy avatar Jun 29 '21 00:06 bergundy

Hey @bergundy I have been reading through webpack's config code, and I don't see what environment variable would influence webpack outside of NODE_ENV, and DEBUG. Both being not set when I run the examples fyi.

Ty for the change though. I think it makes sense given isolated-vm doesn't allow eval by default.

zomble avatar Jun 30 '21 23:06 zomble

I'm going to reopen this issue since using a non eval based devtool (#145) causes stack traces to loose the original filename which will make it extremely hard for users to debug failures. I'll ask the isolated-vm maintainer for some help since we cannot reproduce this.

bergundy avatar Jul 06 '21 15:07 bergundy

@zomble do you by any chance have node aliased? Can you post the output of which node and env (omit any sensitive information of course)?

bergundy avatar Jul 06 '21 20:07 bergundy

$ which node
/home/user/.nvm/versions/node/v14.17.1/bin/node

$ env
SHELL=/bin/bash
SESSION_MANAGER=local/host:@/tmp/.ICE-unix/43615,unix/host:/tmp/.ICE-unix/43615
QT_ACCESSIBILITY=1
COLORTERM=truecolor
XDG_CONFIG_DIRS=/etc/xdg/xdg-ubuntu:/etc/xdg
XDG_MENU_PREFIX=gnome-
GNOME_DESKTOP_SESSION_ID=this-is-deprecated
NVM_IOJS_ORG_MIRROR=https://iojs.org/dist
GTK2_MODULES=overlay-scrollbar
LANGUAGE=en_AU:en
MANDATORY_PATH=/usr/share/gconf/ubuntu.mandatory.path
GNOME_SHELL_SESSION_MODE=ubuntu
SSH_AUTH_SOCK=/run/user/1000/keyring/ssh
XMODIFIERS=@im=ibus
DESKTOP_SESSION=ubuntu
SSH_AGENT_PID=43580
GTK_MODULES=gail:atk-bridge
PWD=/home/user
LOGNAME=user
XDG_SESSION_DESKTOP=ubuntu
XDG_SESSION_TYPE=x11
MANPATH=/home/user/.nvm/versions/node/v14.17.1/share/man:/usr/local/man:/usr/local/share/man:/usr/share/man
GPG_AGENT_INFO=/run/user/1000/gnupg/S.gpg-agent:0:1
XAUTHORITY=/run/user/1000/gdm/Xauthority
GJS_DEBUG_TOPICS=JS ERROR;JS LOG
WINDOWPATH=2
HOME=/home/user
USERNAME=user
IM_CONFIG_PHASE=1
LANG=en_AU.UTF-8
LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.zst=01;31:*.tzst=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.wim=01;31:*.swm=01;31:*.dwm=01;31:*.esd=01;31:*.jpg=01;35:*.jpeg=01;35:*.mjpg=01;35:*.mjpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00;36:*.spx=00;36:*.xspf=00;36:
XDG_CURRENT_DESKTOP=ubuntu:GNOME
VTE_VERSION=6003
GNOME_TERMINAL_SCREEN=/org/gnome/Terminal/screen/d5c771fd_c36b_43ef_bff4_860d15b7c91a
INVOCATION_ID=fc0a94a6696649eb98c2d568714a95c3
MANAGERPID=43369
GJS_DEBUG_OUTPUT=stderr
NVM_DIR=/home/user/.nvm
LESSCLOSE=/usr/bin/lesspipe %s %s
XDG_SESSION_CLASS=user
TERM=xterm-256color
DEFAULTS_PATH=/usr/share/gconf/ubuntu.default.path
LESSOPEN=| /usr/bin/lesspipe %s
USER=user
GNOME_TERMINAL_SERVICE=:1.106
DISPLAY=:1
SHLVL=1
NVM_CD_FLAGS=
QT_IM_MODULE=ibus
XDG_RUNTIME_DIR=/run/user/1000
NVM_NODEJS_ORG_MIRROR=https://nodejs.org/dist
JOURNAL_STREAM=9:78150
XDG_DATA_DIRS=/usr/share/ubuntu:/home/user/.local/share/flatpak/exports/share:/var/lib/flatpak/exports/share:/usr/local/share/:/usr/share/:/var/lib/snapd/desktop:/var/lib/snapd/desktop
PATH=/home/user/.nvm/versions/node/v14.17.1/bin:/home/user/.cargo/bin:/home/user/bin:/home/user/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/local/go/bin:/home/user/.mos/bin:/home/user/.pulumi/bin
GDMSESSION=ubuntu
DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus
NVM_BIN=/home/user/.nvm/versions/node/v14.17.1/bin
_=/usr/bin/env

zomble avatar Jul 06 '21 23:07 zomble

I don't see anything here that would cause node to disable code generation from strings. Thanks for posting.

bergundy avatar Jul 07 '21 01:07 bergundy

@zomble IDK if you've been following the issue in isolated-vm but can you check if you get the "right" error when installing isolated-vm from main: Code generation from large string was denied? https://github.com/laverdet/isolated-vm/issues/251

bergundy avatar Jul 12 '21 15:07 bergundy

@bergundy this has started happening in samples-node as of v0.2.5 for me as well. Didn't happen in v0.2.4.

This comment is the likely explanation: my default maxIsolateMemoryMB is 30944.29296875 and I get the below error

$ npm run schedule-workflow

> [email protected] schedule-workflow /home/val/Workspace/temporalio/samples-node/hello-world
> node ./src/starter

WorkflowExecutionFailedError: Code generation from strings disallowed for this context
    at Connection.untilComplete (/home/val/Workspace/temporalio/samples-node/hello-world/node_modules/@temporalio/client/lib/index.js:204:19)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async Object.start (/home/val/Workspace/temporalio/samples-node/hello-world/node_modules/@temporalio/client/lib/index.js:284:25)
    at async run (/home/val/Workspace/temporalio/samples-node/hello-world/src/starter/index.js:10:18)

If I increase maxIsolateMemoryMB to 66250, my hello world example works fine. If I only increase maxIsolateMemoryMB to 65000, I get the same error. This would seem to indicate that the isolate is somehow eval()-ing an 8 GB string. Does this help in any way? As far as I can tell, the webpack compiled code is only 5 MB, so I haven't been able to guess where this huge eval() might be coming from.

vkarpov15 avatar Jul 15 '21 23:07 vkarpov15

So I've managed to reproduce this on my mac. Interestingly, the error appears if with the isolate memory limits of:

  • 30944.29296875
  • 30944 But not with these values:
  • 65000 (more than I have on my 16GB MBP)
  • 200

I'll post this back in the isolated-vm issue

bergundy avatar Jul 16 '21 18:07 bergundy

Looks like the fix in isolated-vm should allow us to revert #145, I'm adding this issue to the beta milestone.

bergundy avatar Aug 29 '21 14:08 bergundy