Skip to content

module: allow overriding linked requests for a ModuleWrap #59527

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

legendecas
Copy link
Member

@legendecas legendecas commented Aug 19, 2025

This allows overriding linked requests for a ModuleWrap. The
statusOverride in vm.SourceTextModule could call moduleWrap.link
a second time when statusOverride of linking is set to undefined.

Overriding of linked requests should be no harm but better to be
avoided. However, this will require a follow-up fix on statusOverride
in vm.SourceTextModule.link.

Fixes: #59480

This allows overriding linked requests for a `ModuleWrap`. The
`statusOverride` in `vm.SourceTextModule` could call `moduleWrap.link`
a second time when `statusOverride` of `linking` is set to undefined.

Overriding of linked requests should be no harm but better to be
avoided. However, this will require a follow-up fix on `statusOverride`
in `vm.SourceTextModule`.
@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/loaders
  • @nodejs/vm

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. labels Aug 19, 2025
Copy link

codecov bot commented Aug 19, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.89%. Comparing base (3810024) to head (8b1f4eb).
⚠️ Report is 45 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #59527      +/-   ##
==========================================
+ Coverage   89.86%   89.89%   +0.03%     
==========================================
  Files         656      656              
  Lines      193141   193135       -6     
  Branches    37893    37888       -5     
==========================================
+ Hits       173561   173617      +56     
+ Misses      12103    12054      -49     
+ Partials     7477     7464      -13     
Files with missing lines Coverage Δ
src/module_wrap.cc 75.42% <ø> (+0.28%) ⬆️

... and 30 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@legendecas legendecas added module Issues and PRs related to the module subsystem. vm Issues and PRs related to the vm subsystem. labels Aug 19, 2025
Copy link
Member

@joyeecheung joyeecheung left a comment

Choose a reason for hiding this comment

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

Code LGTM though I am a bit confused by the PR description

The statusOverride in vm.SourceTextModule could call moduleWrap.link
a second time when statusOverride of linking is set to undefined.

It's a plain property AFAICT. It seems the more likely cause is that there isn't sufficient guard in the link method to prevent calling the native link method again on a module from the cache that has already called link? Though as long as instantiate() is not called, that seems fine and can be allowed.

@legendecas
Copy link
Member Author

It's a plain property AFAICT. It seems the more likely cause is that there isn't sufficient guard in the link method to prevent calling the native link method again on a module from the cache that has already called link? Though as long as instantiate() is not called, that seems fine and can be allowed.

The statusOverride is set to linking at the begining of the [kLink] method, and reset to undefined at the end of it:

this.#statusOverride = 'linking';

this.#statusOverride = undefined;

This means that the status of the SourceTextModule can regress after [kLink], from linking to unlinked, and causes the race condition.

@legendecas legendecas added the request-ci Add this label to start a Jenkins CI on a PR. label Aug 21, 2025
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Aug 21, 2025
@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ Issues and PRs that require attention from people who are familiar with C++. module Issues and PRs related to the module subsystem. needs-ci PRs that need a full CI run. vm Issues and PRs related to the vm subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Jest unit tests failing after upgrading to 24.6.X
4 participants