Quick fix to avoid deadlock while streaming federated response

pull/46/head
Tpt 4 years ago
parent 240e09c3ac
commit 19e96c73ce
  1. 17
      server/src/main.rs

@ -25,7 +25,7 @@ use oxigraph::model::{GraphName, NamedNode};
use oxigraph::sparql::{Query, QueryOptions, QueryResult, QueryResultFormat, ServiceHandler}; use oxigraph::sparql::{Query, QueryOptions, QueryResult, QueryResultFormat, ServiceHandler};
use oxigraph::RocksDbStore; use oxigraph::RocksDbStore;
use std::fmt; use std::fmt;
use std::io::BufReader; use std::io::{BufReader, Cursor};
use std::str::FromStr; use std::str::FromStr;
use url::form_urlencoded; use url::form_urlencoded;
@ -335,8 +335,14 @@ impl ServiceHandler for HttpService {
request.append_header(headers::ACCEPT, "application/sparql-results+xml"); request.append_header(headers::ACCEPT, "application/sparql-results+xml");
request.set_body(query.to_string()); request.set_body(query.to_string());
let response = block_on(async { self.client.send(request).await })?; //TODO: response streaming
let syntax = if let Some(content_type) = response.content_type() { let response: Result<(Option<Mime>, Vec<u8>)> = block_on(async {
let mut response = self.client.send(request).await?;
Ok((response.content_type(), response.body_bytes().await?))
});
let (content_type, data) = response?;
let syntax = if let Some(content_type) = content_type {
QueryResultFormat::from_media_type(content_type.essence()).ok_or_else(|| { QueryResultFormat::from_media_type(content_type.essence()).ok_or_else(|| {
format_err!( format_err!(
"Unexpected federated query result type from {}: {}", "Unexpected federated query result type from {}: {}",
@ -347,10 +353,7 @@ impl ServiceHandler for HttpService {
} else { } else {
QueryResultFormat::Xml QueryResultFormat::Xml
}; };
Ok( Ok(QueryResult::read(Cursor::new(data), syntax).map_err(Error::from)?)
QueryResult::read(BufReader::new(SyncAsyncReader::from(response)), syntax)
.map_err(Error::from)?,
)
} }
} }

Loading…
Cancel
Save