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

fix(workflow): Fix multiple context leaks in reuseV8Context executor #1605

Merged
merged 17 commits into from
Jan 24, 2025

Conversation

mjameswh
Copy link
Contributor

@mjameswh mjameswh commented Jan 17, 2025

What was changed

  • Fix multiple context leaks and bugs in the reuseV8Context executor:

Note: this is a second round over #1519. The code has changed considerably since the first previous review.

@mjameswh mjameswh requested a review from a team as a code owner January 17, 2025 19:25
Copy link
Member

@bergundy bergundy left a comment

Choose a reason for hiding this comment

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

Overall looks like an improvement to me. Thanks!

Copy link
Contributor

@antlai-temporal antlai-temporal left a comment

Choose a reason for hiding this comment

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

It seems we don't deep freeze Sets and Maps. Is this a concern? Do we need to document this somehow?

Comment on lines 236 to 237
if (Object.isFrozen(object)) return object;

Copy link
Contributor

Choose a reason for hiding this comment

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

Can an object be frozen but not deepFrozen? If not, add a comment....

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure what needs to be clarified here. The official typedoc on Object.freeze() already indicates that freezing is shallow, and generally well known to advanced JS devs.

Comment on lines 1 to 2
// DONOTMERGE -- DO NOT REVIEW THIS FILE

Copy link
Contributor

Choose a reason for hiding this comment

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

Is this comment correct? Do you need to remove this file?

Comment on lines 111 to 117
AsyncLocalStorage,
URL,
URLSearchParams,
assert,
TextEncoder,
TextDecoder,
AbortController,
Copy link
Contributor

Choose a reason for hiding this comment

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

Do any of these need to be deep frozen, or we assume they won't be abused...?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They will get deep frozen at the same time as all other global variables, after loading the script.

@mjameswh
Copy link
Contributor Author

It seems we don't deep freeze Sets and Maps. Is this a concern? Do we need to document this somehow?

That limitation is documented in deepFreeze()'s typedoc. Not a concern at this point because there should be no instance of Map or Set in globalThis after V8 context initialization, nor directly in one of our preloaded modules (i.e. the SDK itself). I had previously added coverage for those because I used a Map as part of the V8 context swapping algorithm, but no longer need it.

@mjameswh
Copy link
Contributor Author

I moved deepFreeze() to reusable-vm.ts (rather than the common package) as some implementation decisions (e.g. freezing functions, not freezing prototypes, not handling Maps and Sets, etc) are specific to the Reusable VM Workflow Sandbox use case, and may not be appropriate for other use cases. It therefore doesn't seem appropiate to consider this as a reusable utility function.

@mjameswh mjameswh merged commit 411a6fe into temporalio:main Jan 24, 2025
22 checks passed
@mjameswh mjameswh deleted the fix-reusev8context-reassign-bug branch January 24, 2025 00:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants