From 027b386514e68371e5ad3075a8d2c2986d44cf77 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Fri, 13 Sep 2024 11:21:26 +0200 Subject: [PATCH] Avoid stack overflow when fetching deeply nested comments (#124) --- src/fetch/object_id.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/fetch/object_id.rs b/src/fetch/object_id.rs index ce52c43..3f0676b 100644 --- a/src/fetch/object_id.rs +++ b/src/fetch/object_id.rs @@ -146,6 +146,10 @@ where Object::read_from_id(*id, data).await } + /// Fetch object from origin instance over HTTP, then verify and parse it. + /// + /// Uses Box::pin to wrap futures to reduce stack size and avoid stack overflow when + /// when fetching objects recursively. async fn dereference_from_http( &self, data: &Data<::DataType>, @@ -154,7 +158,7 @@ where where ::Error: From, { - let res = fetch_object_http(&self.0, data).await; + let res = Box::pin(fetch_object_http(&self.0, data)).await; if let Err(Error::ObjectDeleted(url)) = res { if let Some(db_object) = db_object { @@ -166,8 +170,8 @@ where let res = res?; let redirect_url = &res.url; - Kind::verify(&res.object, redirect_url, data).await?; - Kind::from_json(res.object, data).await + Box::pin(Kind::verify(&res.object, redirect_url, data)).await?; + Box::pin(Kind::from_json(res.object, data)).await } /// Returns true if the object's domain matches the one defined in [[FederationConfig.domain]].