fix(page_service client): correctly deserialize pagestream errors (#6302)

Before this PR, we wouldn't advance the underlying `Bytes`'s cursor.

fixes https://github.com/neondatabase/neon/issues/6298
This commit is contained in:
Christian Schwarz
2024-01-09 10:22:43 +01:00
committed by GitHub
parent 9bf7664049
commit 4b6004e8c9

View File

@@ -2,7 +2,7 @@ pub mod partitioning;
use std::{
collections::HashMap,
io::Read,
io::{BufRead, Read},
num::{NonZeroU64, NonZeroUsize},
time::SystemTime,
};
@@ -813,9 +813,10 @@ impl PagestreamBeMessage {
PagestreamBeMessage::GetPage(PagestreamGetPageResponse { page: page.into() })
}
Tag::Error => {
let buf = buf.get_ref();
let cstr = std::ffi::CStr::from_bytes_until_nul(buf)?;
let rust_str = cstr.to_str()?;
let mut msg = Vec::new();
buf.read_until(0, &mut msg)?;
let cstring = std::ffi::CString::from_vec_with_nul(msg)?;
let rust_str = cstring.to_str()?;
PagestreamBeMessage::Error(PagestreamErrorResponse {
message: rust_str.to_owned(),
})