bun icon indicating copy to clipboard operation
bun copied to clipboard

Implement `promiseHooks` from `node:v8`

Open bkniffler opened this issue 1 year ago ā€¢ 10 comments

What is the problem this feature would solve?

When trying to use temporal sdk (https://github.com/temporalio/sdk-typescript), getting error

node:v8 createHook is not yet implemented in Bun

Its used right here: https://github.com/temporalio/sdk-typescript/blob/3ce098be042e86d26ea5b433508a480503cb09b2/packages/worker/src/workflow/vm-shared.ts#L198

What is the feature you are proposing to solve the problem?

Implement createHook.

What alternatives have you considered?

Ask temporal to not use createHook, but probably out of reach since its needed to isolate the VM scope.

bkniffler avatar Sep 28 '23 10:09 bkniffler

We'd have to think about if this is worth implementing, since it could have a performance impact. (it tracks all promises) However, even if it is feasible, it's not a high priority.

Electroid avatar Sep 28 '23 16:09 Electroid

@Electroid Is there any update on this?

alirezabonab avatar Nov 27 '23 08:11 alirezabonab

Sadly the Temporal Typescript SDK does not work without createHook šŸ˜©

I'd love to have it at least as an opt-in if the performance impact is big.

Ping @lorensr

danieldunderfelt avatar Feb 05 '24 20:02 danieldunderfelt

What's the status on this? Is an implementation of createHook planned?

loicnestler avatar Mar 30 '24 20:03 loicnestler

I'm the author of the code you linked in the Temporal TypeScript SDK. Promise hooks are optional, they allow us to capture the stack trace of all running functions in a workflow. I'm not sure if there's more of a gap for running our SDK on top of Bun but we can look into it. Apart from promise hooks, we use Node's vm and worker_threads modules, AsyncLocalStorage, and rely heavily on Rust Neon bindings.

bergundy avatar May 16 '24 12:05 bergundy

@bergundy if Promise Hooks are optional is there a way to disable them so that we can use Bun. There is a linked issue on the Temporal project.

paradoxloop avatar Oct 01 '24 16:10 paradoxloop

Can bun simply keep silent about this instead of throw an error, if there is no plan to implement this in short time. Just like what deno did in this PR: https://github.com/denoland/deno/pull/25979/files

maybe just use warnNotImplementedOnce in here: https://github.com/oven-sh/bun/blob/25fcbed8d187742faedfe2ff7ce413c059a3c774/src/js/node/v8.ts#L101-L117

or just simply remove the promiseHooks object

axe-me avatar Oct 11 '24 05:10 axe-me

#14485 seems like the way to go. If it ends up not getting merged, we may be able to do something on the Temporal SDK side, it should be easy to edit the SDK files post install to remove the use of promise hooks and confirm. Iā€™m subscribed to this issue, wondering if this is the last hurdle for running the Temporal SDK on bun.

bergundy avatar Oct 11 '24 14:10 bergundy

@bergundy since this PR hasn't been merged yet, is there any chance that Temporal can do checks if the promiseHooks are available in the runtime?

Even if this was merged, the plans from Bun maintainers would be to warn in console that the API is not available, which wouldn't be ideal if Temporal API doesn't check for the API implementation in the first place

cortopy avatar Dec 08 '24 21:12 cortopy

I'm no longer maintaining the Temporal SDK but I will forward this request to @mjameswh.

bergundy avatar Dec 08 '24 23:12 bergundy

Has the situation progressed?

ngomezcn avatar Jan 16 '25 10:01 ngomezcn

For information: the requirement on promiseHooks has been relaxed in Temporal SDK. The fix is currently on the main branch, it will be included in the next patch release (no ETA, but that will be in the next few days).

That is, we now ignore errors thrown while registering promiseHooks, and simply continue without support for __stack_trace and __enhanced_stack_trace queries.

Further investigation will be required to determine either there are other blockers to using Temporal SDK on Bun. Hopefully, we're getting close.

mjameswh avatar Jan 16 '25 15:01 mjameswh