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(watch): preserve ProcState::file_fetcher between restarts #15466

Merged
merged 43 commits into from Jan 10, 2023

Conversation

nayeemrmn
Copy link
Collaborator

Fixes #15465.

@bartlomieju bartlomieju added this to the 1.25 milestone Aug 15, 2022
Copy link
Member

@bartlomieju bartlomieju left a comment

Choose a reason for hiding this comment

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

@nayeemrmn please rebase

cli/proc_state.rs Outdated Show resolved Hide resolved
cli/main.rs Outdated Show resolved Hide resolved
Copy link
Member

@bartlomieju bartlomieju left a comment

Choose a reason for hiding this comment

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

@nayeemrmn this looks good to me, but could we test it somehow?

Copy link
Member

@bartlomieju bartlomieju 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 for looking into this!

@nayeemrmn
Copy link
Collaborator Author

nayeemrmn commented Aug 18, 2022

Looks like the test from this PR is hanging frequently on either debug or release linux, can't reproduce locally. I'll try actually changing the watched file content on the second write...

@nayeemrmn nayeemrmn marked this pull request as draft August 18, 2022 15:05
@nayeemrmn
Copy link
Collaborator Author

Yeah I don't know what's happening with this test. It hangs on one different job each time, but when I put an explicit panic at the end of the function it gets hit. @bartlomieju Anything you can see that's wrong with the test?

@nayeemrmn
Copy link
Collaborator Author

@bartlomieju Finally figured out the problem: 8d58477, debugging with timestamps shows that the file modification in the test can happen between these lines and I guess the watcher misses the event because of that. Files should be watched before printing the finished message

@bartlomieju
Copy link
Member

@nayeemrmn nice, I will try to review the PR tonight

cli/proc_state.rs Outdated Show resolved Hide resolved
@@ -304,7 +335,7 @@ impl ProcState {
.map(|s| (s, ModuleKind::Esm))
.collect::<Vec<_>>();

if !reload_on_watch && !has_root_npm_specifier {
if !has_root_npm_specifier {
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure if this branch is needed anymore, IIRC I only had problems with it because of reload_on_watch

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The alternative would be making this an unconditional block. I believe we want to skip this short circuiting logic if there are npm roots since GraphData::check() doesn't account for those (this could be cleaned up in a separate PR)

@nayeemrmn nayeemrmn marked this pull request as ready for review December 18, 2022 21:27
@bartlomieju
Copy link
Member

Thanks for fixing the PR Nayeem; I will review it after the holiday break.

Copy link
Member

@dsherret dsherret left a comment

Choose a reason for hiding this comment

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

Nice. LGTM!

@@ -1355,12 +1354,14 @@ pub async fn run_tests_with_watch(
let no_check = ps.options.type_check_mode() == TypeCheckMode::None;
let test_options = &test_options;

let ps = RefCell::new(ps);
Copy link
Member

Choose a reason for hiding this comment

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

Now that I'm seeing it I'm a bit worried this might cause unexpected bugs - since ProcState is internally an Arc a lot of APIs could have cloned it and hold onto a copy of that Arc. Even if we create a new Arc in reset_for_file_watcher some code might hold onto the old copy. Does that make sense? Are am I overanalyzing it and essentially anything that can hold onto ProcState gets torn down between restarts?

Copy link
Collaborator Author

@nayeemrmn nayeemrmn Jan 10, 2023

Choose a reason for hiding this comment

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

Well ProcState's fields are either (1) immutable config, (2) mutable data that gets defaulted on reset, or (3) interior mutable fields with their own Arcs which are preserving-ly cloned on reset. If there were an old lingering ProcState inner, the issue would be if (2) and (3) started conflicting since (3) is being affected by a future run. That can be avoided by being strict about what fields are (3) -- should be strictly additive stuff that won't be overwritten between resets. If there's an bug it should just mean that more fields need to be defaulted on reset.. I think

Copy link
Member

Choose a reason for hiding this comment

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

Okay, makes sense. Thanks for investigating

Copy link
Member

@bartlomieju bartlomieju left a comment

Choose a reason for hiding this comment

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

LGTM too

@bartlomieju bartlomieju merged commit 71ea4ef into denoland:main Jan 10, 2023
dsherret pushed a commit that referenced this pull request Jan 13, 2023
This commit changes "ProcState" to store "file_fetcher" field in an "Arc",
allowing it to be preserved between restarts and thus keeping the state
alive between the restarts. File watchers for "deno test" and "deno bench"
now reset "ProcState" between restarts.
dsherret pushed a commit that referenced this pull request Jan 13, 2023
This commit changes "ProcState" to store "file_fetcher" field in an "Arc",
allowing it to be preserved between restarts and thus keeping the state
alive between the restarts. File watchers for "deno test" and "deno bench"
now reset "ProcState" between restarts.
@nayeemrmn nayeemrmn deleted the watch-file-fetcher branch January 16, 2023 19:36
bartlomieju added a commit to bartlomieju/deno that referenced this pull request Jan 30, 2023
bartlomieju added a commit that referenced this pull request Jan 30, 2023
nayeemrmn added a commit to nayeemrmn/deno that referenced this pull request Feb 3, 2023
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.

bug: --watch --reload will reload on every file change
3 participants