-
Hey everyone, I'm working on a database with an HTTP frontend based on axum. I met some issue when I handle POST request with BodyStream. My handler checks many parameters and if the incoming data is valid it receives the body. If something is wrong it returns an error: pub async fn write_record(
State(components): State<Arc<RwLock<HttpServerComponents>>>,
headers: HeaderMap,
Path(path): Path<HashMap<String, String>>,
Query(params): Query<HashMap<String, String>>,
mut stream: BodyStream,
) -> Result<(), HttpError> {
let bucket = path.get("bucket_name").unwrap();
check_permissions(
Arc::clone(&components),
headers.clone(),
WriteAccessPolicy {
bucket: bucket.clone(),
},
)?;
if !params.contains_key("ts") {
return Err(HttpError::unprocessable_entity(
"'ts' parameter is required",
));
}
// many other checks
while let Some(chunk) = stream.next().await {
let mut writer = writer.write().unwrap();
let chunk = match chunk {
Ok(chunk) => chunk,
Err(e) => {
writer.write(Chunk::Error)?;
error!("Error while receiving data: {}", e);
return Err(HttpError::from(e));
}
};
writer.write(Chunk::Data(chunk))?;
}
writer.write().unwrap().write(Chunk::Last(Bytes::new()))?;
Ok(())
} It works perfectly if there is no error happening, but if the server returns an HTTP error, on the client side I have sometimes (!!!) an communication error (broken pipe). Looks like the client is still trying to stream the data but the server interrupts it. I feel that I have to handle the case with BodyStream in a special manner but I don't see how. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
Returning a server error (such as 500) doesn't interrupt the response stream. Sounds like an issue with your client? |
Beta Was this translation helpful? Give feedback.
-
The issue was fixed after I added the "Expect:100-continue" header to a request on the client side. |
Beta Was this translation helpful? Give feedback.
The issue was fixed after I added the "Expect:100-continue" header to a request on the client side.