From 64f798492c5d7abfef8be9837ae0703cda43b48e Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Fri, 30 Jun 2017 10:49:18 -0600 Subject: Fix thread safety issues in aio, chdir, and wait tests They have four problems: * The chdir tests change the process's cwd, which is global. Protect them all with a mutex. * The wait tests will reap any subprocess, and several tests create subprocesses. Protect them all with a mutex so only one subprocess-creating test will run at a time. * When a multithreaded test forks, the child process can sometimes block in the stack unwinding code. It blocks on a mutex that was held by a different thread in the parent, but that thread doesn't exist in the child, so a deadlock results. Fix this by immediately calling std::process:exit in the child processes. * My previous attempt at thread safety in the aio tests didn't work, because anonymous MutexGuards drop immediately. Fix this by naming the SIGUSR2_MTX MutexGuards. Fixes #251 --- test/sys/test_aio.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'test/sys/test_aio.rs') diff --git a/test/sys/test_aio.rs b/test/sys/test_aio.rs index 7945aaf8..7e2bef63 100644 --- a/test/sys/test_aio.rs +++ b/test/sys/test_aio.rs @@ -8,7 +8,6 @@ use std::io::{Write, Read, Seek, SeekFrom}; use std::ops::Deref; use std::os::unix::io::AsRawFd; use std::rc::Rc; -use std::sync::Mutex; use std::sync::atomic::{AtomicBool, Ordering}; use std::{thread, time}; use tempfile::tempfile; @@ -233,8 +232,6 @@ fn test_write() { lazy_static! { pub static ref SIGNALED: AtomicBool = AtomicBool::new(false); - // protects access to SIGUSR2 handlers, not just SIGNALED - pub static ref SIGUSR2_MTX: Mutex<()> = Mutex::new(()); } extern fn sigfunc(_: c_int) { @@ -246,7 +243,8 @@ extern fn sigfunc(_: c_int) { #[test] #[cfg_attr(any(all(target_env = "musl", target_arch = "x86_64"), target_arch = "mips"), ignore)] fn test_write_sigev_signal() { - let _ = SIGUSR2_MTX.lock().expect("Mutex got poisoned by another test"); + #[allow(unused_variables)] + let m = ::SIGUSR2_MTX.lock().expect("Mutex got poisoned by another test"); let sa = SigAction::new(SigHandler::Handler(sigfunc), SA_RESETHAND, SigSet::empty()); @@ -376,7 +374,8 @@ fn test_lio_listio_nowait() { #[cfg(not(any(target_os = "ios", target_os = "macos")))] #[cfg_attr(any(target_arch = "mips", target_env = "musl"), ignore)] fn test_lio_listio_signal() { - let _ = SIGUSR2_MTX.lock().expect("Mutex got poisoned by another test"); + #[allow(unused_variables)] + let m = ::SIGUSR2_MTX.lock().expect("Mutex got poisoned by another test"); const INITIAL: &'static [u8] = b"abcdef123456"; const WBUF: &'static [u8] = b"CDEF"; let rbuf = Rc::new(vec![0; 4].into_boxed_slice()); -- cgit v1.2.3