From 0e0d29d2286cbc43039bdd136f9573c455c7bea0 Mon Sep 17 00:00:00 2001 From: Tim Zhang Date: Tue, 18 Apr 2023 23:01:30 +0800 Subject: [PATCH] agent: Fix ut issue caused by fd double closed Never ever try to close the same fd double times, even in a unit test. A file descriptor is a number which will be reused, so when you close the same number twice you may close another file descriptor in the second time and then there will be an error 'Bad file descriptor (os error 9)' while the wrongly closed fd is being used. Fixes: #6679 Signed-off-by: Tim Zhang (cherry picked from commit 53c749a9de89ead493a91f823d580c6cec9125e0) --- src/agent/src/main.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/agent/src/main.rs b/src/agent/src/main.rs index d8e9fc828..18c408a27 100644 --- a/src/agent/src/main.rs +++ b/src/agent/src/main.rs @@ -436,9 +436,8 @@ mod tests { let msg = format!("test[{}]: {:?}", i, d); let (rfd, wfd) = unistd::pipe2(OFlag::O_CLOEXEC).unwrap(); defer!({ - // rfd is closed by the use of PipeStream in the crate_logger_task function, - // but we will attempt to close in case of a failure - let _ = unistd::close(rfd); + // XXX: Never try to close rfd, because it will be closed by PipeStream in + // create_logger_task() and it's not safe to close the same fd twice time. unistd::close(wfd).unwrap(); });