Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

chore(wasix): Additional logging in wasix HTTP client #5174

Merged
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
14 changes: 11 additions & 3 deletions lib/wasix/src/http/reqwest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ impl ReqwestHttpClient {
self
}

#[tracing::instrument(skip_all, fields(method=?request.method, url=%request.url))]
async fn request(&self, request: HttpRequest) -> Result<HttpResponse, anyhow::Error> {
let method = reqwest::Method::try_from(request.method.as_str())
.with_context(|| format!("Invalid http method {}", request.method))?;
Expand All @@ -53,6 +54,7 @@ impl ReqwestHttpClient {
};
let client = builder.build().context("failed to create reqwest client")?;

tracing::debug!("sending http request");
let mut builder = client.request(method, request.url.as_str());
for (header, val) in &request.headers {
builder = builder.header(header, val);
Expand All @@ -71,9 +73,11 @@ impl ReqwestHttpClient {

let status = response.status();

tracing::debug!(status=?status, "received http response");

// Download the body.
#[cfg(not(feature = "js"))]
let data = if let Some(timeout) = self.response_body_chunk_timeout {
let data = if let Some(timeout_duration) = self.response_body_chunk_timeout {
// Download the body with a chunk timeout.
// The timeout prevents long stalls.

Expand All @@ -85,7 +89,7 @@ impl ReqwestHttpClient {
// is kept. Only if no chunk was downloaded within the timeout a
// timeout error is raised.
'OUTER: loop {
let timeout = tokio::time::sleep(timeout);
let timeout = tokio::time::sleep(timeout_duration);
pin_utils::pin_mut!(timeout);

let mut chunk_count = 0;
Expand Down Expand Up @@ -113,9 +117,11 @@ impl ReqwestHttpClient {

_ = &mut timeout => {
if chunk_count == 0 {
tracing::warn!(timeout= "timeout while downloading response body");
return Err(anyhow::anyhow!("Timeout while downloading response body"));
} else {
// Timeout, but chunks were still downloaded, so
tracing::debug!(downloaded_body_size_bytes=%buf.len(), "download progress");
// Timeout, but chunks were downloaded, so
// just continue with a fresh timeout.
continue 'OUTER;
}
Expand All @@ -131,6 +137,8 @@ impl ReqwestHttpClient {
#[cfg(feature = "js")]
let data = response.bytes().await?.to_vec();

tracing::debug!(body_size_bytes=%data.len(), "downloaded http response body");

Ok(HttpResponse {
status,
redirected: false,
Expand Down
Loading