temporalio / sdk-typescript

Temporal TypeScript SDK
Other
534 stars 105 forks source link

[Feature Request] Run temporal worker in bun #1334

Open Code2Life opened 10 months ago

Code2Life commented 10 months ago

Bun worker can not work Issue

I tried to use bun as temporal worker, when running temporal client it looked perfect, the workflow created with HTTP2+gRPC, which just supported in bun.js last month.

But when I ran temporal worker it can not work, even bun.sh had implement v8 compatible vm context sandbox. Firstly I found this issue: image

Then, i tried to comment out the createHook code block, this error disappeared, but the core-bridge was broken

2024-01-10T08:41:16.131Z [INFO] webpack 5.89.0 compiled successfully in 486 ms
2024-01-10T08:41:16.132Z [INFO] Workflow bundle created { size: '0.74MB' }
2024-01-10T08:41:16.284520Z  INFO temporal_sdk_core::worker: Initializing worker task_queue=hello-world namespace=default
thread '<unnamed>' panicked at 'Hash table capacity overflow', /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/hashbrown-0.13.2/src/raw/mod.rs:90:40
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
2024-01-10T08:41:16.286Z [INFO] Worker state changed { state: 'RUNNING' }
2024-01-10T08:41:16.290075Z  INFO next_workflow_activation: temporal_sdk_core::worker: Initiated shutdown task_queue=hello-world namespace=default task_queue=hello-world
2024-01-10T08:41:16.291Z [INFO] Worker state changed { state: 'DRAINED' }
2024-01-10T08:41:16.291Z [INFO] Worker state changed { state: 'STOPPED' }
thread 'core' panicked at 'Workflow processing terminates cleanly: Error joining workflow processing thread: Ok("Hash table capacity overflow")', sdk-core/core/src/worker/mod.rs:409:14
 96 |         }
 97 |         this.shutDownRequested = true;
 98 |         await this.send({ type: 'destroy' });
 99 |         const exitCode = await this.workerThread.terminate();
100 |         if (exitCode !== exports.TERMINATED_EXIT_CODE) {
101 |             throw new core_bridge_1.UnexpectedError(`Failed to terminate Worker thread, exit code: ${exitCode}`);
                                      ^

Additional context

Both Temporal and bun are really amazing. Since bun provide many out-of-box features and better performance than node.js, It would be great if temporal sdk can support bun worker.

izakfilmalter commented 10 months ago

Would love to use bun instead!!!!

bergundy commented 10 months ago

We know what we need to do to get the SDK working on bun but it'll be a significant lift and may not be prioritized just yet.

bergundy commented 10 months ago

I too hope we will support more JS runtimes including bun and deno.

brettgoulder commented 9 months ago

nodejs recommends against using createHook:

Stability: 1 - Experimental. Please migrate away from this API, if you can. We do not recommend using the createHook, AsyncHook, and executionAsyncResource APIs as they have usability issues, safety risks, and performance implications. Async context tracking use cases are better served by the stable AsyncLocalStorage API. If you have a use case for createHook, AsyncHook, or executionAsyncResource beyond the context tracking need solved by AsyncLocalStorage or diagnostics data currently provided by Diagnostics Channel, please open an issue at https://github.com/nodejs/node/issues describing your use case so we can create a more purpose-focused API.

bergundy commented 9 months ago

The SDK uses v8 promise hooks createHook, not async hooks. We need this functionality for showing workflow stack traces.

loicnestler commented 7 months ago

Any updates on this? 👀

maurovanetti commented 7 months ago

In case someone wondered: No, Bun 1.1.0 (out since Monday) does not support Temporal yet. :disappointed:

error: node:v8 createHook is not yet implemented in Bun.
      at new NotImplementedError (internal:shared:20:28)
      at internal:shared:3:70
      at node:v8:3:46
      at node:v8:77:30
      at setPromiseHook (/home/mauro/Codice/in4matic/bun/temporal/node_modules/@temporalio/worker/lib/workflow/vm-shared.js:208:33)
      at install (/home/mauro/Codice/in4matic/bun/temporal/node_modules/@temporalio/worker/lib/workflow/vm-shared.js:140:13)
      at /home/mauro/Codice/in4matic/bun/temporal/node_modules/@temporalio/worker/lib/workflow/reusable-vm.js:139:8
      at create (/home/mauro/Codice/in4matic/bun/temporal/node_modules/@temporalio/worker/lib/workflow/reusable-vm.js:138:21)
      at /home/mauro/Codice/in4matic/bun/temporal/node_modules/@temporalio/worker/lib/workflow/workflow-worker-thread.js:10:36
      at handleRequest (/home/mauro/Codice/in4matic/bun/temporal/node_modules/@temporalio/worker/lib/workflow/workflow-worker-thread.js:6:35)
hscj87 commented 5 months ago

nodejs recommends against using createHook:

Stability: 1 - Experimental. Please migrate away from this API, if you can. We do not recommend using the createHook, AsyncHook, and executionAsyncResource APIs as they have usability issues, safety risks, and performance implications. Async context tracking use cases are better served by the stable AsyncLocalStorage API. If you have a use case for createHook, AsyncHook, or executionAsyncResource beyond the context tracking need solved by AsyncLocalStorage or diagnostics data currently provided by Diagnostics Channel, please open an issue at https://github.com/nodejs/node/issues describing your use case so we can create a more purpose-focused API.

How to disable using createHook to avoid this error?

andreyvital commented 4 months ago

I have the same question as @hscj87 and the same request as the original issue text. Commenting just to bump up this thread.

axe-me commented 1 month ago

it would be great to be able to run temporal worker with bun!

tenkoverse commented 1 month ago

@bergundy Deno 2 has removed promiseHooks stubs (https://github.com/denoland/deno/issues/25977) to provide an environment where temporals check for promiseHooks is skipped https://github.com/temporalio/sdk-typescript/blob/faa64225a7f57154931a38c1fe612fc6520943b2/packages/worker/src/workflow/vm-shared.ts#L199-L202

I now have temporal clients and workers successfully working in deno 2.

I would love to know the implications for having an enviroment where there are no promise hooks. What do I lose using deno to run a temporal worker instead of using node (with version >=16.14)

bergundy commented 1 month ago

We use promise hooks to capture stack traces that are used in the stack trace query feature that gives visibility into where your workflow is blocked at any given point.