Skip to content

Commit 8f4ee2e

Browse files
committed
Remove unnecessary retry logic
1 parent 8db4591 commit 8f4ee2e

1 file changed

Lines changed: 15 additions & 35 deletions

File tree

src/jail/linux/mod.rs

Lines changed: 15 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use super::{Jail, JailConfig};
44
use anyhow::{Context, Result};
55
use iptables::IPTablesRule;
66
use std::process::{Command, ExitStatus};
7-
use std::time::{SystemTime, UNIX_EPOCH};
87
use tracing::{debug, error, info, warn};
98

109
/// Linux namespace network configuration constants
@@ -103,42 +102,23 @@ impl LinuxJail {
103102

104103
/// Create the network namespace
105104
fn create_namespace(&mut self) -> Result<()> {
106-
// Try to create namespace with retry logic for concurrent safety
107-
for attempt in 0..3 {
108-
let output = Command::new("ip")
109-
.args(["netns", "add", &self.namespace_name])
110-
.output()
111-
.context("Failed to execute ip netns add")?;
112-
113-
if output.status.success() {
114-
info!("Created network namespace: {}", self.namespace_name);
115-
self.namespace_created = true;
116-
return Ok(());
117-
}
118-
119-
let stderr = String::from_utf8_lossy(&output.stderr);
120-
if stderr.contains("File exists") && attempt < 2 {
121-
// Namespace name collision, regenerate and retry
122-
warn!(
123-
"Namespace {} already exists, regenerating name",
124-
self.namespace_name
125-
);
126-
// Regenerate with new timestamp
127-
let timestamp = SystemTime::now()
128-
.duration_since(UNIX_EPOCH)
129-
.unwrap()
130-
.as_micros();
131-
let new_id = format!("{:07}", timestamp % 10_000_000);
132-
self.namespace_name = format!("httpjail_{}", new_id);
133-
self.veth_host = format!("veth_h_{}", new_id);
134-
self.veth_ns = format!("veth_n_{}", new_id);
135-
continue;
136-
}
105+
// Create namespace (unique jail_id ensures no collisions)
106+
let output = Command::new("ip")
107+
.args(["netns", "add", &self.namespace_name])
108+
.output()
109+
.context("Failed to execute ip netns add")?;
137110

138-
anyhow::bail!("Failed to create namespace: {}", stderr);
111+
if output.status.success() {
112+
info!("Created network namespace: {}", self.namespace_name);
113+
self.namespace_created = true;
114+
Ok(())
115+
} else {
116+
anyhow::bail!(
117+
"Failed to create namespace {}: {}",
118+
self.namespace_name,
119+
String::from_utf8_lossy(&output.stderr)
120+
)
139121
}
140-
141-
anyhow::bail!("Failed to create namespace after 3 attempts")
142122
}
143123

144124
/// Set up veth pair for namespace connectivity

0 commit comments

Comments
 (0)