-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
src, loader: return promises from link #18394
Conversation
src/module_wrap.cc
Outdated
@@ -173,9 +177,11 @@ void ModuleWrap::Link(const FunctionCallbackInfo<Value>& args) { | |||
} | |||
Local<Promise> resolve_promise = resolve_return_value.As<Promise>(); | |||
obj->resolve_cache_[specifier_std].Reset(env->isolate(), resolve_promise); | |||
|
|||
USE(promises->Set(mod_context, specifier, resolve_promise)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should crash if the Set fails (promises->Set().FromJust()
). USE is only for when we don’t care about the result of execution, and should be used sparingly.
Why is this patch preferred over #18249 (comment)? Edit: answered on IRC:
|
lib/internal/loader/ModuleJob.js
Outdated
const jobs = []; | ||
const promises = this.module.link(async (specifier) => { | ||
const job = await this.loader.getModuleJob(specifier, url); | ||
jobs.push(job); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we were to keep a jobs
array, we would want to store the promises from getModuleJob
to ensure determinism in the order of jobs
.
0fbccf9
to
8e1fb42
Compare
Returns the promises created by link so that they can be awaited to get rid of race conditions while resolving and loading modules.
be04b4a
to
f936321
Compare
comments above addressed |
Returns the promises created by link so that they can be awaited to get rid of race conditions while resolving and loading modules. PR-URL: nodejs#18394 Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Landed in edbcf7c |
Unfortunately this requires a corresponding change in |
@@ -173,9 +177,11 @@ void ModuleWrap::Link(const FunctionCallbackInfo<Value>& args) { | |||
} | |||
Local<Promise> resolve_promise = resolve_return_value.As<Promise>(); | |||
obj->resolve_cache_[specifier_std].Reset(env->isolate(), resolve_promise); | |||
|
|||
promises->Set(mod_context, specifier, resolve_promise).FromJust(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line does not set array items (i.e. it does not set promises[0]
, promises[1]
, etc.) It sets promises[specifier]
i.e. some non-array properties of promises
object. So, the array returned from this function is not populated properly and the corresponding await SafePromise.all(promises)
does not do what was expected. There should be i
instead of specifier
, i.e., promises->Set(mod_context, i, resolve_promise).FromJust();
, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yea i actually just caught this while testing my changes for vm.Module. i'm kinda sad this pr landed without tests, as it doesn't work. i have another pr incoming anyway, which will fix this, and includes tests that will actually ensure this behavior does what it is supposed to do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should've caught this while reviewing... my bad as well.
This lands cleanly, but is causing v9.x to break during compilation. Should it be backported?
|
@MylesBorins These kinds of errors can be fixed by adding |
@addaleax thanks, that worked |
Returns the promises created by link so that they can be awaited to get rid of race conditions while resolving and loading modules. PR-URL: #18394 Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
This commit fixes up some issues in nodejs#18394. * Switch vm.Module internals to use the new link method properly * Fix bug with ModuleWrap::Link * Add tests for ModuleWrap::Link PR-URL: nodejs#18509 Fixes: nodejs#18249 Refs: nodejs#18394 Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Returns the promises created by link so that they can be awaited to get rid of race conditions while resolving and loading modules. PR-URL: #18394 Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Returns the promises created by link so that they can be awaited to get rid of race conditions while resolving and loading modules. PR-URL: #18394 Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Should this be backported to |
Returns the promises created by link so that they can be awaited to get rid of race conditions while resolving and loading modules. PR-URL: nodejs#18394 Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
This commit fixes up some issues in nodejs#18394. * Switch vm.Module internals to use the new link method properly * Fix bug with ModuleWrap::Link * Add tests for ModuleWrap::Link PR-URL: nodejs#18509 Fixes: nodejs#18249 Refs: nodejs#18394 Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Returns the promises created by link so that they can be awaited to get
rid of race conditions while resolving and loading modules.
closes #18249
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
loader, src