-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[API Proposal]: Add PipeOptions.FirstPipeInstance enum value #76984
Comments
Tagging subscribers to this area: @dotnet/area-system-io Issue DetailsBackground and motivationIt's not possible for an app hosting multiple named pipe connections to verify that no one else is using the pipe name when it starts. For example, Kestrel is looking at adding a named pipe transport, and when we start Kestrel we want to verify that no one else is using the configured pipe name. Named pipes have a built-in option for checking this - FILE_FLAG_FIRST_PIPE_INSTANCE. See https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-createnamedpipea .NET doesn't expose this option. While it is automatically set if the max number of pipe instances is 1, there is no way to explicitly set this option. runtime/src/libraries/System.IO.Pipes/src/System/IO/Pipes/NamedPipeServerStream.Windows.cs Lines 121 to 124 in c59b517
If the Note that validation on the // NamedPipeServerStream errors when passed this pipe option
pipeOptions |= (PipeOptions)0x00080000; API Proposalnamespace System.IO.Pipes
{
[Flags]
public enum PipeOptions
{
FirstPipeInstance = unchecked((int)0x00080000)
}
} API Usageprivate NamedPipeServerStream CreateServerStream(bool firstStream)
{
var pipeOptions = PipeOptions.Asynchronous | PipeOptions.WriteThrough;
if (_options.CurrentUserOnly)
{
pipeOptions |= PipeOptions.CurrentUserOnly;
}
if (firstStream)
{
pipeOptions |= PipeOptions.FirstPipeInstance;
}
return new NamedPipeServerStream(
_endpoint.PipeName,
PipeDirection.InOut,
NamedPipeServerStream.MaxAllowedServerInstances,
PipeTransmissionMode.Byte,
pipeOptions,
inBufferSize: 0,
outBufferSize: 0);
} Alternative DesignsNo response RisksNo response
|
Thanks for the proposal, it looks to me like a good case to expose the option.
I also thought of just excluding FILE_FLAG_FIRST_PIPE_INSTANCE from said validation, but the history shows that it is in place since Pipe code was ported over to core. Regarding the proposed name, I'm not sure if As an alternative proposal I suggest |
I went with |
namespace System.IO.Pipes
{
[Flags]
public enum PipeOptions
{
FirstPipeInstance = unchecked((int)0x00080000)
}
} |
Named pipes support in Kestrel is limited to Windows only. Ideally, |
Hi People, I'd like to take this up and contribute a PR. |
@Tarun047 that would be very helpful. Please feel free to do so. |
I've created a commit in my fork I wanted to make sure these are the changes that we should be doing before creating a PR and I don't want to create a When I build my local repository with the following command it's throwing a build error which says the call site is reachable on Unix but the parameter PipeOptions.FirstPipeInstance itself is supported only on Windows. But I don't see why this is a problem, because even I would really appreciate any help in this regard and let me know if I'm missing something here. |
Background and motivation
It's not possible for an app hosting multiple named pipe connections to verify that no one else is using the pipe name when it starts.
For example, Kestrel is looking at adding a named pipe transport, and when we start Kestrel we want to verify that no one else is using the configured pipe name:
Named pipes have a built-in option for checking this - FILE_FLAG_FIRST_PIPE_INSTANCE. See https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-createnamedpipea
.NET doesn't expose this option. While it is automatically set if the max number of pipe instances is 1, there is no way to explicitly set this option.
runtime/src/libraries/System.IO.Pipes/src/System/IO/Pipes/NamedPipeServerStream.Windows.cs
Lines 121 to 124 in c59b517
If the
PipeOptions.FirstPipeInstance
options was available, then Kestrel would create the firstNamedPipeServerStream
with it the option to verify that there is no existing pipe with that name and create subsequentNamedPipeServerStream
instances without the option.Note that validation on the
NamedPipeServerStream
ctor currently prevents the enum value having FILE_FLAG_FIRST_PIPE_INSTANCE value added to it. e.g.API Proposal
API Usage
Alternative Designs
It still alludes at the name of the Windows API flag and conveys "throw if already exists".
Risks
No response
The text was updated successfully, but these errors were encountered: