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(engine-dylib): do not keep temp file and delete it automatically #2547

Merged
merged 4 commits into from
Sep 1, 2021

Conversation

bnjjj
Copy link
Contributor

@bnjjj bnjjj commented Aug 31, 2021

close #2501

Description

This PR plan to fix the issue #2501
I know the implementation using Drop trait is not the best way to implement it. Maybe I need more knowledge about engine lifecycle or adding a trait method to clean any artifacts we create when using an engine. Feel free to give me more details about how I could implement this in a better way.

…asmerio#2501

Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
@@ -58,6 +58,12 @@ pub struct DylibArtifact {
frame_info_registration: Mutex<Option<GlobalFrameInfoRegistration>>,
}

impl Drop for DylibArtifact {
fn drop(&mut self) {
std::fs::remove_file(&self.dylib_path).expect("cannot delete the temporary artifact");
Copy link
Member

Choose a reason for hiding this comment

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

This will drop the file always, however there is only one scenario where we should do it.

deserialize (which creates a temporal file and then callsdeserialize_from_file_unchecked) should delete the temporal file, however deserialize_from_file (which doesn't create a temporal file) should not delete the file (since it was provided by the user), we can provably have a new field specifying if the file is temporal or not and delete it on such case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok got it thank you, btw what's your policies regarding to error in this case ? Do you prefer to panic as I do here or just display a log ?

Copy link
Member

Choose a reason for hiding this comment

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

I think it might be better to gracefully dismiss the error in case the worst case scenario is reached, so logging seems like a better option than a panic.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's what I think too. Updated, thanks :)

Copy link
Member

Choose a reason for hiding this comment

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

That's great, will review now!

Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
Copy link
Member

@syrusakbary syrusakbary left a comment

Choose a reason for hiding this comment

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

Looks great! Merging soonish (as soon as bors test and merges)

@syrusakbary
Copy link
Member

bors r+

bors bot added a commit that referenced this pull request Sep 1, 2021
2547: fix(engine-dylib): do not keep temp file and delete it automatically r=syrusakbary a=bnjjj

close #2501

# Description
This PR plan to fix the issue #2501 
I know the implementation using Drop trait is not the best way to implement it. Maybe I need more knowledge about engine lifecycle or adding a trait method to clean any artifacts we create when using an engine. Feel free to give me more details about how I could implement this in a better way.


Co-authored-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
@bors
Copy link
Contributor

bors bot commented Sep 1, 2021

Build failed:

Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
@bnjjj
Copy link
Contributor Author

bnjjj commented Sep 1, 2021

Sorry I had to add a feature on dependency tracing for log in this crate

@syrusakbary
Copy link
Member

No worries.

bors r+

@bors
Copy link
Contributor

bors bot commented Sep 1, 2021

@bors bors bot merged commit 378550a into wasmerio:master Sep 1, 2021
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.

Temp files are not removed in dylib engine
2 participants