From 903fb4e39eecb944495b01903b253ba5748d6d20 Mon Sep 17 00:00:00 2001 From: Cole Helbling Date: Fri, 26 Jul 2024 10:21:52 -0700 Subject: [PATCH] fixup: stream error logging The call to `into_inner()` discards the wrapper type constructed by `map_err()`. So instead, `map_err()` the actual stream, and call `Body::from_stream` on the wrapped stream. --- server/src/api/binary_cache.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/server/src/api/binary_cache.rs b/server/src/api/binary_cache.rs index 05e6630..242f0f1 100644 --- a/server/src/api/binary_cache.rs +++ b/server/src/api/binary_cache.rs @@ -18,7 +18,7 @@ use axum::{ Router, }; use futures::stream::BoxStream; -use http_body_util::BodyExt; +use futures::TryStreamExt as _; use serde::Serialize; use tokio_util::io::ReaderStream; use tracing::instrument; @@ -217,11 +217,11 @@ async fn get_nar( match storage.download_file_db(remote_file, false).await? { Download::Url(url) => Ok(Redirect::temporary(&url).into_response()), Download::AsyncRead(stream) => { - let stream = ReaderStream::new(stream); - let body = Body::from_stream(stream).map_err(|e| { + let stream = ReaderStream::new(stream).map_err(|e| { tracing::error!("Stream error: {e}"); e - }).into_inner(); + }); + let body = Body::from_stream(stream); Ok(body.into_response()) } @@ -254,11 +254,11 @@ async fn get_nar( // TODO: Make num_prefetch configurable // The ideal size depends on the average chunk size - let merged = merge_chunks(chunks, streamer, storage, 2); - let body = Body::from_stream(merged).map_err(|e| { + let merged = merge_chunks(chunks, streamer, storage, 2).map_err(|e| { tracing::error!("Stream error: {e}"); e - }).into_inner(); + }); + let body = Body::from_stream(merged); Ok(body.into_response()) }