Skip to content

Commit 35ef8b8

Browse files
committed
Limit the number of targets that can be built
1 parent ccf21a6 commit 35ef8b8

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

.github/ISSUE_TEMPLATE/sandbox-limits-increase-request.md

+1
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@ assignees: ''
1616

1717
**Requested RAM limit:**
1818
**Requested timeout:**
19+
**Requested number of targets:**
1920

2021
**Why your crate needs the resource increases:**

src/docbuilder/limits.rs

+10
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::time::Duration;
55

66
pub(crate) struct Limits {
77
memory: usize,
8+
targets: usize,
89
timeout: Duration,
910
networking: bool,
1011
max_log_size: usize,
@@ -15,6 +16,7 @@ impl Default for Limits {
1516
Self {
1617
memory: 3 * 1024 * 1024 * 1024, // 3 GB
1718
timeout: Duration::from_secs(15 * 60), // 15 minutes
19+
targets: 10,
1820
networking: false,
1921
max_log_size: 100 * 1024, // 100 KB
2022
}
@@ -37,6 +39,9 @@ impl Limits {
3739
if let Some(timeout) = row.get::<_, Option<i32>>("timeout_seconds") {
3840
limits.timeout = Duration::from_secs(timeout as u64);
3941
}
42+
if let Some(targets) = row.get::<_, Option<u32>>("max_targets") {
43+
limits.targets = targets as usize;
44+
}
4045
}
4146

4247
Ok(limits)
@@ -58,6 +63,10 @@ impl Limits {
5863
self.max_log_size
5964
}
6065

66+
pub(crate) fn targets(&self) -> usize {
67+
self.targets
68+
}
69+
6170
pub(crate) fn for_website(&self) -> BTreeMap<String, String> {
6271
let time_scale = |v| scale(v, 60, &["seconds", "minutes", "hours"]);
6372
let size_scale = |v| scale(v, 1024, &["bytes", "KB", "MB", "GB"]);
@@ -74,6 +83,7 @@ impl Limits {
7483
} else {
7584
res.insert("Network access".into(), "blocked".into());
7685
}
86+
res.insert("Maximum number of build targets".into(), self.targets.to_string());
7787
res
7888
}
7989
}

src/docbuilder/rustwide_builder.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,8 @@ impl RustwideBuilder {
354354
successful_targets.push(res.target.clone());
355355

356356
// Then build the documentation for all the targets
357-
for target in other_targets {
357+
// Limit the number of targets so that no one can try to build all 200000 possible targets
358+
for target in other_targets.into_iter().take(limits.targets()) {
358359
debug!("building package {} {} for {}", name, version, target);
359360
self.build_target(
360361
target,

0 commit comments

Comments
 (0)