Skip to content

Commit 9387864

Browse files
committed
fix: increase container limits and add startup cleanup
- Increase max_containers_per_challenge from 10 to 100 - Increase max_containers_per_owner from 50 to 200 - Add cleanup_stale_containers() on broker startup to remove leftover containers from previous runs (force remove)
1 parent f0ef63d commit 9387864

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed

crates/secure-container-runtime/src/broker.rs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ impl ContainerBroker {
8585
// Ensure network exists
8686
self.ensure_network().await?;
8787

88+
// Cleanup stale containers from previous runs
89+
if let Err(e) = self.cleanup_stale_containers().await {
90+
warn!("Failed to cleanup stale containers: {}", e);
91+
}
92+
8893
loop {
8994
match listener.accept().await {
9095
Ok((stream, _)) => {
@@ -872,6 +877,52 @@ impl ContainerBroker {
872877
Ok(())
873878
}
874879

880+
/// Cleanup stale containers from previous runs
881+
async fn cleanup_stale_containers(&self) -> anyhow::Result<()> {
882+
use bollard::container::ListContainersOptions;
883+
884+
// Find all containers managed by this broker
885+
let label_filter = format!("{}=true", labels::MANAGED);
886+
let mut filters = HashMap::new();
887+
filters.insert("label", vec![label_filter.as_str()]);
888+
889+
let options = ListContainersOptions {
890+
all: true,
891+
filters,
892+
..Default::default()
893+
};
894+
895+
let containers = self.docker.list_containers(Some(options)).await?;
896+
let count = containers.len();
897+
898+
if count == 0 {
899+
info!("No stale containers to cleanup");
900+
return Ok(());
901+
}
902+
903+
info!("Cleaning up {} stale containers from previous run", count);
904+
905+
for container in containers {
906+
if let Some(id) = container.id {
907+
let short_id = &id[..12.min(id.len())];
908+
debug!("Removing stale container: {}", short_id);
909+
910+
// Force remove (stop + remove)
911+
let options = RemoveContainerOptions {
912+
force: true,
913+
..Default::default()
914+
};
915+
916+
if let Err(e) = self.docker.remove_container(&id, Some(options)).await {
917+
warn!("Failed to remove stale container {}: {}", short_id, e);
918+
}
919+
}
920+
}
921+
922+
info!("Stale container cleanup complete");
923+
Ok(())
924+
}
925+
875926
/// Ensure the challenge network exists
876927
async fn ensure_network(&self) -> anyhow::Result<()> {
877928
let networks = self.docker.list_networks::<String>(None).await?;

crates/secure-container-runtime/src/policy.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ impl Default for SecurityPolicy {
6262
max_memory_bytes: 8 * 1024 * 1024 * 1024, // 8GB
6363
max_cpu_cores: 4.0,
6464
max_pids: 512,
65-
max_containers_per_challenge: 10,
66-
max_containers_per_owner: 50,
65+
max_containers_per_challenge: 100,
66+
max_containers_per_owner: 200,
6767
allowed_mount_prefixes: vec!["/tmp/".to_string(), "/var/lib/platform/".to_string()],
6868
forbidden_mount_paths: forbidden,
6969
allow_privileged: false,

0 commit comments

Comments
 (0)