Skip to content

Commit 54cb26a

Browse files
lmvasquezgmeta-codesync[bot]
authored andcommitted
Cap concurrency in location_to_hg_changeset_id
Summary: ⚠️ **This diff was generated by M-O** -- an AI code-quality bot that produces one small, surgical Rust cleanup per day in fbcode/eden/mononoke. walle_clean location_to_hg_changeset_id uses future::try_join_all to convert N bonsai changeset IDs to Hg IDs after resolving a commit-graph location. try_join_all polls all N futures concurrently with no bound. The count parameter comes from the client's commit_location_to_hash request and can represent hundreds of changesets (Sapling's segment-based protocol sends linear segments of 100-500+ entries). Unbounded fan-out on user-controlled N risks saturating the derived-data SQL store and is flagged as a production anti-pattern (S493741, S552025). Replace try_join_all with stream::iter(...).buffered(100) to cap in-flight derivation calls at 100. buffered (not buffer_unordered) preserves the ordering of the result vec, matching the original semantics. Remove the now- unused futures::future import. Differential Revision: D103610505 fbshipit-source-id: 08e52faed4af38c45157277d55589cc3758d0f1c
1 parent f813882 commit 54cb26a

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

  • eden/mononoke/mononoke_api_hg/src

eden/mononoke/mononoke_api_hg/src/repo.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ use futures::StreamExt;
3939
use futures::TryStream;
4040
use futures::TryStreamExt;
4141
use futures::compat::Stream01CompatExt;
42-
use futures::future;
4342
use futures::stream;
4443
use futures_util::try_join;
4544
use hgproto::GettreepackArgs;
@@ -530,12 +529,16 @@ impl<R: MononokeRepo> HgRepoContext<R> {
530529
.repo_ctx()
531530
.location_to_changeset_id(cs_location, count)
532531
.await?;
533-
let hg_id_futures = result_csids
534-
.iter()
535-
.map(|result_csid| self.repo().derive_hg_changeset(self.ctx(), *result_csid));
536-
future::try_join_all(hg_id_futures)
532+
stream::iter(result_csids)
533+
.map(|bcs_id| async move {
534+
self.repo()
535+
.derive_hg_changeset(self.ctx(), bcs_id)
536+
.await
537+
.map_err(MononokeError::from)
538+
})
539+
.buffered(100)
540+
.try_collect()
537541
.await
538-
.map_err(MononokeError::from)
539542
}
540543

541544
/// This provides the same functionality as

0 commit comments

Comments
 (0)