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

FsLoader makes blocking function calls in async context #67

Open
damooo opened this issue Nov 7, 2023 · 1 comment
Open

FsLoader makes blocking function calls in async context #67

damooo opened this issue Nov 7, 2023 · 1 comment

Comments

@damooo
Copy link

damooo commented Nov 7, 2023

FsLoader makes blocking function calls like std::fs::File::open(), buf_reader.read_to_string() etc. in async block. This will lead to starvation of async runtime, and also probable panics.

async move {
match self.filepath(vocabulary, &url) {
Some(filepath) => {
let file = File::open(filepath).map_err(Error::IO)?;
let mut buf_reader = BufReader::new(file);
let mut contents = String::new();
buf_reader
.read_to_string(&mut contents)
.map_err(Error::IO)?;
let doc = (*self.parser)(vocabulary, &url, contents.as_str())
.map_err(Error::Parse)?;
Ok(RemoteDocument::new(
Some(url),
Some("application/ld+json".parse().unwrap()),
doc,
))
}
None => Err(Error::NoMountPoint),
}
}
.boxed()

Expected behaviour:

Should use non blocking async functions, like those in tokio::fs instead.

@timothee-haudebourg
Copy link
Owner

This is a good point, but I am not comfortable with forcing an async runtime. I am not up to date with efforts to provide a runtime independent async I/O API.

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

No branches or pull requests

2 participants