From ea1a173854af892e92af95790b5726d64d04edf0 Mon Sep 17 00:00:00 2001 From: Fupan Li Date: Thu, 30 Dec 2021 11:25:41 +0800 Subject: [PATCH] agent: fix the issue of creating new namespaces for agent The tokio's spawn will only create an future async task instead of a new real thread, thus executing unshare to create a new namespace in tokio's async task would make the agent process to join in the new created namespace, which isn't expected. Thus, we'd better to to the unshare in a real thread to prevent moving the agent process into a new namespace. Fixes: #3369 Signed-off-by: Fupan Li --- src/agent/src/namespace.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/agent/src/namespace.rs b/src/agent/src/namespace.rs index c821a0acb1..fd8bfbec28 100644 --- a/src/agent/src/namespace.rs +++ b/src/agent/src/namespace.rs @@ -100,7 +100,7 @@ impl Namespace { self.path = new_ns_path.clone().into_os_string().into_string().unwrap(); let hostname = self.hostname.clone(); - let new_thread = tokio::spawn(async move { + let new_thread = std::thread::spawn(move || { if let Err(err) = || -> Result<()> { let origin_ns_path = get_current_thread_ns_path(ns_type.get()); @@ -148,7 +148,7 @@ impl Namespace { }); new_thread - .await + .join() .map_err(|e| anyhow!("Failed to join thread {:?}!", e))??; Ok(self)