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: prevent multiple downloads of same file #2477

Merged
merged 8 commits into from
Jun 24, 2019

Conversation

bartlomieju
Copy link
Member

@bartlomieju bartlomieju commented Jun 8, 2019

This PR is proof-of-concept to prevent multiple downloads of same file as described in #2442.

For example given in #2442, here's downloads before this patch:

deno_dev run --reload --allow-read test.ts
[192/192] Compiling https://raw.githubusercontent.com/denoland/deno_std/v0.7.0/http/server.ts

And after patch:

deno_dev run --reload --allow-read test.ts
[39/39] Compiling https://raw.githubusercontent.com/denoland/deno_std/v0.7.0/media_types/mod.ts

It builds on idea of State.compiled - once file is downloaded it's placed in HashSet to prevent another download of same file. Code is hacky to prevent necessity of huge changes in DenoDir - I don't intend this to be merged but rather be another POV for refactor of DenoDir.

CC @kitsonk

Fixes #2442

@kitsonk
Copy link
Contributor

kitsonk commented Jun 8, 2019

It makes sense to me, but I don't know if I am really the best authority. My Rust knowledge is just enough to be dangerous.

@bartlomieju bartlomieju mentioned this pull request Jun 9, 2019
@hayd hayd mentioned this pull request Jun 16, 2019
@bartlomieju
Copy link
Member Author

@ry could you take a look at this PR?

Tests are failing but I believe they are not replicating "real life" scenario - I don't think it's possible to change headers for certain file during same run - then we'd need to change setup of tests a little bit.

Also I had other idea: update fetch_remote_source_async so it caches whole result of download (including code, content type and redirects).

cli/deno_dir.rs Outdated Show resolved Hide resolved
@bartlomieju bartlomieju force-pushed the test-prevent_multiple_downloads branch from 4889a5c to d14adf2 Compare June 23, 2019 10:17
@bartlomieju
Copy link
Member Author

@ry I think I managed to find solution using initial approach that involves marking which URLs had already been downloaded. It's much simpler compared to saving whole response.

I changed two tests to behave like a real world scenario and added a test for multiple downloads (verifying that headers file modified timestamp is unchanged). Let me know what you think.

But as you said earlier this is definitely to be rewritten from ground up.

@bartlomieju bartlomieju changed the title prevent multiple downloads of same file [do not merge] fix: prevent multiple downloads of same file Jun 23, 2019
cli/deno_dir.rs Outdated Show resolved Hide resolved
cli/deno_dir.rs Show resolved Hide resolved
cli/deno_dir.rs Outdated Show resolved Hide resolved
cli/deno_dir.rs Show resolved Hide resolved
let headers_file_metadata_2 = headers_file_2.metadata().unwrap();
let headers_file_modified_2 = headers_file_metadata_2.modified().unwrap();

assert_eq!(headers_file_modified, headers_file_modified_2);
Copy link
Member

@ry ry Jun 24, 2019

Choose a reason for hiding this comment

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

Very nice! I've been trying to come up with a test for this failure for a long time. I have verified this test does indeed fail when applied to master.

Thank you for solving this bug!

Copy link
Member Author

Choose a reason for hiding this comment

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

Very nice! I've been trying to come up with a test for this failure for a long time. I have verified this test does indeed fail when applied to master.

Thank you for solving this bug!

Great, thanks! 🎉

Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

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

LGTM modulo a few nits...

@ry ry merged commit 3c81cca into denoland:master Jun 24, 2019
@bartlomieju bartlomieju deleted the test-prevent_multiple_downloads branch June 24, 2019 16:05
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.

deno run --reload infinite loop
3 participants