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" ); }