NamedPipe permanently leaks HANDLEs
Inside SelectorInner::drop(), mio does timeout=0 polls of IOCP in an attempt to reap all pending overlapped ops NamedPipes might have submited. This is needed to ensure that all references to named_pipe::Inner get released (which will then call CloseHandle on the pipe). However, it's impossible to guarantee that all NamedPipe reads/writes will complete and get witnessed by the time mio::Poll gets dropped. This leads to the underlying handle of NamedPipe never getting closed.
Test case to reproduce the bug
https://github.com/1c7718e7/mio/commit/94e662736411d0c48cbd23f033cac25304a2cdab
Reproduces on both Windows 11 and Wine 11.5.
Potential fix
https://github.com/1c7718e7/mio/commit/8df3ebcd3c718687e373e44a2f8c0e6d8eb7f8ef
This simply wraps the handle as Mutex<Option> and makes NamedPipe::drop synchronously CloseHandle it. Wrapping it as std::sync::Weak and holding a strong Arc inside NamedPipe is would be another alternative.
Source: tokio-rs/mio