Skip to content

Windows: Cache the pipe filesystem handle#155250

Open
ChrisDenton wants to merge 2 commits intorust-lang:mainfrom
ChrisDenton:pipe-fs
Open

Windows: Cache the pipe filesystem handle#155250
ChrisDenton wants to merge 2 commits intorust-lang:mainfrom
ChrisDenton:pipe-fs

Conversation

@ChrisDenton
Copy link
Copy Markdown
Member

Updates the anonymous pipe handling based on feedback from @lhecker (see #142517 (comment)). This does two things:

  1. Cache the handle to the pipe filesystem so we don't have to reopen it each time.
  2. Use the \Device\NamedPipe\ directly instead of the symlink to it.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Apr 13, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 13, 2026

r? @ibraheemdev

rustbot has assigned @ibraheemdev.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @ChrisDenton, libs
  • @ChrisDenton, libs expanded to 8 candidates
  • Random selection from Mark-Simulacrum, ibraheemdev, jhpratt

Comment thread library/std/src/sys/process/windows/child_pipe.rs Outdated
Also use the `\Device\NamedPipe\` directly instead of the symlink to it.
@ChrisDenton
Copy link
Copy Markdown
Member Author

ChrisDenton commented Apr 14, 2026

r? rust-lang/libs

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 14, 2026

The review request libs corresponds to 7 reviewer(s).
However, none of them are available for a review at this time.
Use r? to specify someone else to assign.

let pipe_fs = {
let path = api::unicode_str!(r"\??\PIPE\");
// Open a handle to the pipe filesystem (`\Device\NamedPipe\`) and cache it.
// This will be used when creating a new anonymous pipe.
Copy link
Copy Markdown
Member

@Mark-Simulacrum Mark-Simulacrum Apr 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we going to get complaints from valgrind (not sure that works on Windows) for a handle leak due to this? Anything preemptive that we could do to indicate it's intentional?

View changes since the review

Copy link
Copy Markdown
Member Author

@ChrisDenton ChrisDenton Apr 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't tend to get those types of complaints for Windows but. sure, I can add a comment explicitly noting this is intentional.

Edit: Windows doesn't have the tight fd limit that unix systems can have so leaking a single handle is less of an issue (the limit for handles is something north of 16 million).

// Open a handle to the pipe filesystem (`\Device\NamedPipe\`) and cache it.
// This will be used when creating a new anonymous pipe.
static PIPE_FS: Atomic<c::HANDLE> = Atomic::<c::HANDLE>::new(ptr::null_mut());
let pipe_fs = if let handle = PIPE_FS.load(Relaxed)
Copy link
Copy Markdown
Member

@Mark-Simulacrum Mark-Simulacrum Apr 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, this feels like it needs to be Acquire coupled with a Release store below, no? Otherwise we're not necessarily seeing the memory initialization. Though probably OK in practice given the interesting memory is in the kernel... right?

View changes since the review

Copy link
Copy Markdown
Contributor

@lhecker lhecker Apr 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah exactly: The NT file handle is kernel-mode only and so access is fully synchronized already.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, all we need to do here is ensure the atomic containing the handle synchronises with itself. For which relaxed is sufficient. It would be a (rather serious, imo) bug in the OS if using a handle across threads risked synchronisation issues around the handle itself.

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants