Windows 命名管道: 在竞争多线程运行时客户端重复丢弃时,出现 STATUS_HEAP_CORRUPTION 进程故障
fn pipe(slot: usize) -> String { format!("\.\pipe\np-crash-repro-{slot}") }
fn main() { let slot: usize = env::args() .nth(2) .and_then(|value| value.parse().ok()) .unwrap_or(0); match env::args().nth(1).as_deref() { Some("server") => server(slot), Some("client") => client(slot), Some("spin") => loop { std::hint::black_box(1); }, _ => supervise(), } }
fn affinity() -> usize { env::var("NP_AFFINITY") .ok() .and_then(|value| value.parse().ok()) .unwrap_or(0b11) }
fn spawn(mode: &str, slot: usize, pin: bool) -> Child { let child = Command::new(env::current_exe().unwrap()) .arg(mode) .arg(slot.to_string()) .stdout(Stdio::null()) .stderr(Stdio::null()) .spawn() .unwrap(); if pin { // Two logical processors, so the runtime's worker threads and its I/O driver preempt each other constantly. Any pair of busy cores reproduces this. let handle = child.as_raw_handle() as windows_sys::Win32::Foundation::HANDLE; unsafe { windows_sys::Win32::System::Threading::SetProcessAffinityMask(handle, affinity()) }; } child }
内容来源: tokio-rs/mio