Cygwin select() returns -1 with errno 0

2025年9月03日 19:36:44 -0700

The problem is that `select` returns -1 with errno 0, so `perror` says `select: 
No error`.
Copied from https://github.com/msys2/msys2-runtime/issues/308 as 
previously website of cygwin is temporary unavailable for me.
Original seen in 
https://github.com/fish-shell/fish-shell/pull/11238/commits/0ad62cea2a9a6606128b182d11b3aac4a62b3b9d
 in https://github.com/fish-shell/fish-shell/pull/11238
It occurs randomly.
![](https://github.com/user-attachments/assets/6e149de7-ca87-4b30-bac7-fb690c153da9)
```
$ fish -c 'ls > /dev/null'
select: No error
```
However when using `strace` this occurs more often. The following example uses 
`strace -f -m syscall,select ./fish -c 'sha256sum fish.exe' &> 
output.txt`.
<details&gt;
<summary&gt;Trimmed output</summary&gt;
```
&nbsp; 627 &nbsp;479850 [fish] fish 1628 pselect: pselect (15, 0x7FFD0C690, 
0x7FFD0C680, 0x7FFD0C670, 0x0, 0x0)
&nbsp; 104 &nbsp;479954 [fish] fish 1628 pselect: to NULL, us -1
&nbsp; 770 &nbsp;480724 [fish] fish 1628 select: sel.always_ready 0
&nbsp;3427 &nbsp;484151 [main] fish 1628 write: write(15, 0x7FFFF9E4C, 1)
&nbsp; &nbsp;89 &nbsp;484240 [main] fish 1628 write: 1 = write(15, 0x7FFFF9E4C, 
1)
&nbsp; &nbsp;53 &nbsp;484293 [pipesel] fish 1628 peek_pipe: read: 
pipe:[12884907236], ready for read: avail 1
&nbsp; 108 &nbsp;484401 [fish] fish 1628 select_stuff::wait: wait_ret 2, m = 3. 
&nbsp;verifying
&nbsp; 101 &nbsp;484502 [fish] fish 1628 set_bits: me 0xA00046280, testing fd 
14 (pipe:[12884907236])
&nbsp; &nbsp;57 &nbsp;484559 [main] fish 1628 read: read(12, 0x7FFFF5DF8, 
16384) nonblocking
&nbsp; 155 &nbsp;484714 [fish] fish 1628 set_bits: ready 1
&nbsp; 114 &nbsp;484828 [fish] fish 1628 set_bits: me 0xA00045C20, testing fd 
12 (pipe:[8589939940])
&nbsp; 117 &nbsp;484945 [fish] fish 1628 set_bits: ready 0
&nbsp; &nbsp;52 &nbsp;484997 [main] fish 1628 read: -1 = read(12, 0x7FFFF5DF8, 
-1), errno 11
&nbsp; &nbsp;53 &nbsp;485050 [fish] fish 1628 select_stuff::wait: res after 
verify 0
&nbsp; 102 &nbsp;485152 [fish] fish 1628 select_stuff::wait: returning 0
&nbsp; &nbsp;51 &nbsp;485203 [main] fish 1628 close: close(12)
&nbsp; &nbsp;52 &nbsp;485255 [fish] fish 1628 select: sel.wait returns 0
&nbsp; 100 &nbsp;485355 [main] fish 1628 fhandler_base::close: closing 
'pipe:[8589939940]' handle 0x2F0
&nbsp; &nbsp;49 &nbsp;485404 [main] fish 1628 close: 0 = close(12)
&nbsp; &nbsp;45 &nbsp;485449 [fish] fish 1628 peek_pipe: pipe:[12884907236], 
already ready for read
&nbsp; &nbsp;52 &nbsp;485501 [main] fish 1628 close: close(13)
&nbsp; &nbsp;51 &nbsp;485552 [fish] fish 1628 set_bits: me 0xA00046280, testing 
fd 14 (pipe:[12884907236])
&nbsp; 108 &nbsp;485660 [fish] fish 1628 set_bits: ready 1
&nbsp; &nbsp;56 &nbsp;485716 [main] fish 1628 fhandler_base::close: closing 
'pipe:[8589939940]' handle 0x2D8
&nbsp; &nbsp;53 &nbsp;485769 [main] fish 1628 close: 0 = close(13)
&nbsp; &nbsp;45 &nbsp;485814 [fish] fish 1628 select_stuff::cleanup: calling 
cleanup routines
&nbsp; 293 &nbsp;486107 [fish] fish 1628 select_stuff::destroy: deleting select 
records
&nbsp; 310 &nbsp;486417 [fish] fish 1628 select_stuff::cleanup: calling cleanup 
routines
&nbsp; 101 &nbsp;486518 [fish] fish 1628 select_stuff::destroy: deleting select 
records
&nbsp; 107 &nbsp;486625 [fish] fish 1628 pselect: -1 = select (15, 0x7FFD0C690, 
0x7FFD0C680, 0x7FFD0C670, 0x0), errno 0
select &nbsp;890 &nbsp;487515 [fish] fish 1628 write: 6 = write(2, 0x100C27640, 
6)
: &nbsp; 208 &nbsp;487723 [fish] fish 1628 write: 2 = write(2, 0x100C5BA30, 2)
No error &nbsp;206 &nbsp;487929 [fish] fish 1628 write: 8 = write(2, 
0x2102D4D35, 8)
&nbsp; 197 &nbsp;488126 [fish] fish 1628 write: 1 = write(2, 0x100C5C791, 1)
```
</details&gt;
The binary can be compiled using following commands with MSYS2.
```
pacman -S gcc mingw-w64-x86_64-rustup
rustup component add rust-src --toolchain nightly-x86_64-pc-windows-gnu
cargo +nightly-x86_64-pc-windows-gnu install -Z build-std --target 
x86_64-pc-cygwin --profile release-with-debug --git 
https://github.com/fish-shell/fish-shell.git --rev d8e5821 --bin fish
```
Note that [`--rev 
d8e5821`](https://github.com/fish-shell/fish-shell/commit/d8e5821a3b8f944cb071b98781680f15ba4effd6)
 is required as workaround is added in 
https://github.com/fish-shell/fish-shell/commit/4508b5b0db7b012ae2c19f4f7aa9df74ac89ea3c.
 Commit history is available 
[here](https://github.com/fish-shell/fish-shell/commits/4508b5b0db7b012ae2c19f4f7aa9df74ac89ea3c/).
Code that trigger `perror` is here.
https://github.com/fish-shell/fish-shell/blob/d8e5821a3b8f944cb071b98781680f15ba4effd6/src/fd_monitor.rs#L390-L395
```rust
let ret = 
fds.check_readable(timeout.map(Timeout::Duration).unwrap_or(Timeout::Forever));
if ret < 0 &amp;&amp; !matches!(errno().0, libc::EINTR | libc::EBADF) {
&nbsp; &nbsp; // Surprising error
&nbsp; &nbsp; perror("select");
}
```
-- 
Problem reports: https://cygwin.com/problems.html
FAQ: https://cygwin.com/faq/
Documentation: https://cygwin.com/docs.html
Unsubscribe info: https://cygwin.com/ml/#unsubscribe-simple

Reply via email to