Skip to content

NamedPipe permanently leaks HANDLEs #1944

Description

@1c7718e7

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

1c7718e7@94e6627

Reproduces on both Windows 11 and Wine 11.5.

Potential fix

1c7718e7@8df3ebc

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugwindowsRelated to the Windows OS.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions