Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix: continue reading ipc on large data #958

Merged
merged 1 commit into from
Jun 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 32 additions & 6 deletions crates/transport-ipc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,6 @@ impl<T: AsyncRead> futures::stream::Stream for ReadJsonStream<T> {
"IPC buffer contains invalid JSON data",
);

if this.buf.len() > CAPACITY {
// buffer is full, we can't decode any more
error!("IPC response too large to decode");
return Ready(None);
}

// this happens if the deserializer is unable to decode a partial object
*this.drained = true;
} else if err.is_eof() {
Expand Down Expand Up @@ -254,4 +248,36 @@ mod tests {
let obj = reader.next().await;
assert!(obj.is_none());
}

#[tokio::test]
async fn test_large_valid() {
let header = b"{\"jsonrpc\":\"2.0\",\"id\":1,\"result\":\"0x";
let filling_zeros = header
.iter()
.chain(vec![b'0'; CAPACITY - header.len()].iter())
.copied()
.collect::<Vec<_>>();

let first_page = filling_zeros.as_ref();
let second_page = b"\"}";

let mock = tokio_test::io::Builder::new()
// partial object
.read(first_page)
// trigger pending read
.wait(std::time::Duration::from_millis(1))
// complete object
.read(second_page)
.build();

let mut reader = ReadJsonStream::new(mock);
poll_fn(|cx| {
let res = reader.poll_next_unpin(cx);
assert!(res.is_pending());
Ready(())
})
.await;
let obj = reader.next().await;
assert!(obj.is_some());
}
}