Skip to content

Commit f433704

Browse files
committed
fix: don't cleanup challenge containers with different suffixes
Server and validator may run on the same host and need separate challenge containers. Each only manages its own container (same suffix).
1 parent 4362a3c commit f433704

File tree

1 file changed

+3
-47
lines changed

1 file changed

+3
-47
lines changed

crates/challenge-orchestrator/src/docker.rs

Lines changed: 3 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -437,17 +437,11 @@ impl DockerClient {
437437
"Generated challenge container name"
438438
);
439439

440-
// Remove existing container if any (same name)
440+
// Remove existing container if any (same name only)
441+
// NOTE: We do NOT clean up containers with different suffixes because
442+
// server and validator may run on the same host and need separate containers
441443
let _ = self.remove_container(&container_name).await;
442444

443-
// Clean up old challenge containers with different suffixes (from previous server restarts)
444-
let challenge_prefix = format!(
445-
"challenge-{}-",
446-
config.name.to_lowercase().replace(' ', "-")
447-
);
448-
self.cleanup_old_challenge_containers(&challenge_prefix, &container_name)
449-
.await;
450-
451445
// Build port bindings - expose on a dynamic port
452446
let mut port_bindings = HashMap::new();
453447
port_bindings.insert(
@@ -781,44 +775,6 @@ impl DockerClient {
781775
Ok(output)
782776
}
783777

784-
/// Clean up old challenge containers with different suffixes
785-
/// This handles the case where the server restarts with a new container ID
786-
async fn cleanup_old_challenge_containers(&self, prefix: &str, exclude_name: &str) {
787-
let options = ListContainersOptions::<String> {
788-
all: true,
789-
..Default::default()
790-
};
791-
792-
let containers = match self.docker.list_containers(Some(options)).await {
793-
Ok(c) => c,
794-
Err(e) => {
795-
warn!(error = %e, "Failed to list containers for cleanup");
796-
return;
797-
}
798-
};
799-
800-
for container in containers {
801-
let names = container.names.unwrap_or_default();
802-
let container_id = match container.id.as_ref() {
803-
Some(id) => id.clone(),
804-
None => continue,
805-
};
806-
807-
// Check if container name matches prefix but is not the current container
808-
let should_remove = names.iter().any(|name| {
809-
let clean_name = name.trim_start_matches('/');
810-
clean_name.starts_with(prefix) && clean_name != exclude_name
811-
});
812-
813-
if should_remove {
814-
info!(container = ?names, "Removing old challenge container from previous server instance");
815-
if let Err(e) = self.remove_container(&container_id).await {
816-
warn!(container = ?names, error = %e, "Failed to remove old container");
817-
}
818-
}
819-
}
820-
}
821-
822778
/// Clean up stale task containers created by challenge evaluations
823779
///
824780
/// This removes containers that match the pattern but excludes:

0 commit comments

Comments
 (0)