Skip to content

Commit 115c936

Browse files
committed
f - Remove ReadAdaptor in favor of reading into a buffer
Using block_on inside ReadAdaptor led to a test occasionally hanging.
1 parent 343b14a commit 115c936

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

lightning-block-sync/src/http.rs

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,12 @@ impl HttpClient {
275275
std::io::ErrorKind::InvalidInput, "unsupported transfer coding"))
276276
} else {
277277
#[cfg(feature = "tokio")]
278-
let reader = ReadAdapter(&mut reader);
278+
let reader = {
279+
// Read the stream into a buffer since chunked_transfer isn't async.
280+
let mut buffer = Vec::new();
281+
reader.read_to_end(&mut buffer).await?;
282+
std::io::Cursor::new(buffer)
283+
};
279284
let mut decoder = chunked_transfer::Decoder::new(reader);
280285
let mut content = Vec::new();
281286
decoder.read_to_end(&mut content)?;
@@ -362,18 +367,6 @@ enum HttpMessageLength {
362367
TransferEncoding(String),
363368
}
364369

365-
/// An adaptor for making `tokio::io::AsyncRead` compatible with interfaces expecting
366-
/// `std::io::Read`. This effectively makes the adapted object synchronous.
367-
#[cfg(feature = "tokio")]
368-
struct ReadAdapter<'a, R: tokio::io::AsyncRead + std::marker::Unpin>(&'a mut R);
369-
370-
#[cfg(feature = "tokio")]
371-
impl<'a, R: tokio::io::AsyncRead + std::marker::Unpin> std::io::Read for ReadAdapter<'a, R> {
372-
fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
373-
futures::executor::block_on(self.0.read(buf))
374-
}
375-
}
376-
377370
/// An HTTP response body in binary format.
378371
pub(crate) struct BinaryResponse(pub(crate) Vec<u8>);
379372

0 commit comments

Comments
 (0)