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: Fix segmentation fault in tests on CPUs with PKU support #471

Merged
merged 4 commits into from
Jan 24, 2024

Conversation

Digifox03
Copy link
Contributor

Due to V8's PKU feature, only the thread that initialized the V8 platform or those spawned from it can access the isolates; other threads will get a segmentation fault. Since each test runs in its thread, they crash on newer CPUs that support PKU.

This issue has two possible solutions:

  1. Initialize the platform once in the main thread.
  2. Turn off the PKU feature during testing.

This issue was already encountered for the deno test command, which was resolved by initializing the platform in the main thread (denoland/deno#20495).

In the case of rust tests, the same solution cannot be used, as the default test runner does not allow running code on the main thread before any test runs.

My proposed solution is to add a feature flag to deno_core, which, when enabled, uses the unprotected platform. An alternative solution could be to call deno_core::JsRuntime::init_platform at the beginning of each test.

This PR will also be a step towards fixing denoland/deno#21439

@CLAassistant
Copy link

CLAassistant commented Jan 23, 2024

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

@mmastrac mmastrac left a comment

Choose a reason for hiding this comment

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

We'll probably need to tweak the features a bit but it looks like the right approach.

core/Cargo.toml Outdated Show resolved Hide resolved
core/runtime/jsruntime.rs Outdated Show resolved Hide resolved
serde_v8/magic/v8slice.rs Show resolved Hide resolved
serde_v8/utils.rs Show resolved Hide resolved
@bartlomieju
Copy link
Member

Do we need to add a Cargo feature here? Maybe we could rely on #[cfg(test)] attribute instead?

@mmastrac
Copy link
Contributor

Do we need to add a Cargo feature here? Maybe we could rely on #[cfg(test)] attribute instead?

I think the problem is that some downstream crates need the PKU workaround.

Copy link
Contributor

@mmastrac mmastrac left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@mmastrac mmastrac merged commit ec8cbe2 into denoland:main Jan 24, 2024
13 checks passed
mmastrac pushed a commit to denoland/deno that referenced this pull request Feb 5, 2024
mmastrac pushed a commit to mmastrac/deno that referenced this pull request Feb 5, 2024
littledivy pushed a commit to denoland/deno that referenced this pull request Feb 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants