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

refactor(cli): use new sanitizer for resources #22125

Merged
merged 10 commits into from Jan 26, 2024
Merged

Conversation

mmastrac
Copy link
Member

@mmastrac mmastrac commented Jan 26, 2024

Step 1 of the Rustification of sanitizers, which unblocks the faster timers.

This replaces the resource sanitizer with a Rust one, using the new APIs in deno_core.

@mmastrac mmastrac changed the title refactor(cli): use new sanitizer for resources [WIP] refactor(cli): use new sanitizer for resources Jan 26, 2024
Comment on lines +9 to +12
[UNORDERED_START]
- The stdin pipe was opened before the test started, but was closed during the test. Do not close resources in a test that were not created during that test.
- A file was opened during the test, but not closed during the test. Close the file handle by calling `file.close()`.
[UNORDERED_END]
Copy link
Member

Choose a reason for hiding this comment

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

Why is it unordered?

Copy link
Member Author

Choose a reason for hiding this comment

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

This PR changes the order of the output but I don't think we should care about that from a test perspective (allowing me to tweak in the future).

The information is what's important here, not the order IMO

Comment on lines +104 to +107
// TODO(mmastrac): until we implement the new timers and op sanitization, these must be ignored in this path
if item_name == "timer" {
continue;
}
Copy link
Member

Choose a reason for hiding this comment

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

What's the consequence of it? Are timers ignored from sanitization altogether?

Copy link
Member Author

Choose a reason for hiding this comment

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

Nope, they are picked up via op sanitization. Timers technically leak both an op and a resource and we were only showing the op before as a side effect of how things were implemented

Comment on lines +142 to +147
fn pretty_resource_name(
name: &str,
) -> (Cow<'static, str>, &'static str, &'static str) {
let (name, action1, action2) = match name {
"fsFile" => ("A file", "opened", "closed"),
"fetchRequest" => ("A fetch request", "started", "finished"),
Copy link
Member

Choose a reason for hiding this comment

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

Can you think of a way to make this data be defined on the Resource trait - that way we can force via type system to have these descriptions. I'm not sure how we'd look them up though.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think we could add a metadata block for resources but it would require a bit of work to add some registration macros.

Comment on lines +181 to +185
fn resource_close_hint(name: &str) -> &'static str {
match name {
"fsFile" => "Close the file handle by calling `file.close()`.",
"fetchRequest" => "Await the promise returned from `fetch()` or abort the fetch with an abort signal.",
"fetchRequestBody" => "Terminate the request body `ReadableStream` by closing or erroring it.",
Copy link
Member

Choose a reason for hiding this comment

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

Ditto

Comment on lines +578 to +585
let op_id_host_recv_message = ops
.iter()
.position(|op| *op == "op_host_recv_message")
.unwrap();
let op_id_host_recv_ctrl = ops
.iter()
.position(|op| *op == "op_host_recv_ctrl")
.unwrap();
Copy link
Member

Choose a reason for hiding this comment

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

Why are these special cased?

Copy link
Member Author

Choose a reason for hiding this comment

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

These are a special case for the existing op sanitization as they are "weird" ops that may appear to leak. These will be used in the follow-up PR.

Comment on lines +603 to +604
// TODO(mmastrac): we should provide an API to poll the event loop until no futher
// progress is made.
Copy link
Member

Choose a reason for hiding this comment

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

This comment is a bit unclear to me - how would we figure out that "no further progress" is made?

Copy link
Member Author

Choose a reason for hiding this comment

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

It would be something like an option to the poll method -- if the option is set we would return "ready" if the event loop did not make progress on ops, modules, timers or anything else (ie dispatch).

We currently return pending whether we did work or not and this would allow a caller to determine when the runtime has "settled" into a steady state.

This probably requires some research.

Copy link
Member

Choose a reason for hiding this comment

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

Should I go ahead with the refactor we discussed in the past, where poll_event_loop would return an enum describing state of the event loop instead of Poll::Pending/Poll::Ready?

@mmastrac mmastrac merged commit 84fb2ad into denoland:main Jan 26, 2024
14 checks passed
bartlomieju added a commit to bartlomieju/deno that referenced this pull request Jan 27, 2024
littledivy pushed a commit that referenced this pull request Feb 1, 2024
Step 1 of the Rustification of sanitizers, which unblocks the faster
timers.

This replaces the resource sanitizer with a Rust one, using the new APIs
in deno_core.
mmastrac added a commit to mmastrac/deno that referenced this pull request Feb 1, 2024
Step 1 of the Rustification of sanitizers, which unblocks the faster
timers.

This replaces the resource sanitizer with a Rust one, using the new APIs
in deno_core.
mmastrac added a commit to denoland/deno_core that referenced this pull request Feb 2, 2024
We needed to revert the resource sanitizer in
denoland/deno#22125 because of a panic in
third-party test code.

The problem was that in certain cases, if the OpDriver was kept alive
either by Rc<ContextState> (in older code) or Rc<OpDriverImpl> (in newer
code), the Tokio task that polls the underlying ops would potentially
poll an op that expected something to be in OpState, but we had already
removed all the items in the OpState by that point.
mmastrac added a commit to mmastrac/deno that referenced this pull request Feb 3, 2024
Step 1 of the Rustification of sanitizers, which unblocks the faster
timers.

This replaces the resource sanitizer with a Rust one, using the new APIs
in deno_core.
mmastrac added a commit to mmastrac/deno that referenced this pull request Feb 5, 2024
Step 1 of the Rustification of sanitizers, which unblocks the faster
timers.

This replaces the resource sanitizer with a Rust one, using the new APIs
in deno_core.
mmastrac added a commit to mmastrac/deno that referenced this pull request Feb 5, 2024
    Step 1 of the Rustification of sanitizers, which unblocks the faster
    timers.

    This replaces the resource sanitizer with a Rust one, using the new APIs
    in deno_core.
mmastrac added a commit to mmastrac/deno that referenced this pull request Feb 5, 2024
    Step 1 of the Rustification of sanitizers, which unblocks the faster
    timers.

    This replaces the resource sanitizer with a Rust one, using the new APIs
    in deno_core.
mmastrac added a commit that referenced this pull request Feb 5, 2024
Originally in #22125
Reverted in #22153 because of #22148

Fixed in deno_core denoland/deno_core#538

Test plan: 

1. Check out: https://github.com/poolifier/poolifier-deno.git

2. `PATH=.../deno/target/release/:$PATH deno task test`

3. `ok | 13 passed (188 steps) | 0 failed (18s)`
littledivy pushed a commit that referenced this pull request Feb 8, 2024
Originally in #22125
Reverted in #22153 because of #22148

Fixed in deno_core denoland/deno_core#538

Test plan: 

1. Check out: https://github.com/poolifier/poolifier-deno.git

2. `PATH=.../deno/target/release/:$PATH deno task test`

3. `ok | 13 passed (188 steps) | 0 failed (18s)`
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.

None yet

2 participants