From c1a43b896ccbfaa1e836268474654cd386d2faa6 Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Thu, 9 Jan 2025 17:30:08 -0600 Subject: [PATCH] Skip select ebadf test under WSLv1 due to a WSL bug WSLv1 won't return EBADF (or any error) if the fd was closed mid-select. --- src/fd_monitor.rs | 2 ++ src/tests/fd_monitor.rs | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/fd_monitor.rs b/src/fd_monitor.rs index 9bf5a1ca5..85c82f9b1 100644 --- a/src/fd_monitor.rs +++ b/src/fd_monitor.rs @@ -384,6 +384,8 @@ impl BackgroundFdMonitor { // in particular it may even close file descriptors that we are waiting on. That is why // we handle EBADF. Note that even if the file descriptor is recycled, we don't invoke // a callback for it unless its ItemID is still present. + // + // Note that WSLv1 doesn't throw EBADF if the fd is closed is mid-select. drop(data); let ret = fds.check_readable( timeout diff --git a/src/tests/fd_monitor.rs b/src/tests/fd_monitor.rs index ca3424e3b..ccd072b9e 100644 --- a/src/tests/fd_monitor.rs +++ b/src/tests/fd_monitor.rs @@ -204,13 +204,18 @@ where #[test] fn test_close_during_select_ebadf() { + use crate::common::{is_windows_subsystem_for_linux as is_wsl, WSL}; let close_it = |read_fd: OwnedFd| { drop(read_fd); None }; let result = do_something_bad_during_select(close_it); + + // WSLv1 does not error out with EBADF if the fd is closed mid-select. + // This is OK because we do not _depend_ on this behavior; the only + // true requirement is that we don't panic in the handling code above. assert!( - matches!(result, Err(libc::EBADF) | Ok(1)), + is_wsl(WSL::V1) || matches!(result, Err(libc::EBADF) | Ok(1)), "select/poll should have failed with EBADF or marked readable" ); }