Skip to content

FsLoader makes blocking function calls in async context #67

@damooo

Description

@damooo

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions