Skip to content
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

Cannot connect NamedPipeClientStream later when constructing it with an existing pipe handle #83073

Open
carlossanlop opened this issue Mar 7, 2023 · 1 comment
Labels
area-System.IO help wanted [up-for-grabs] Good issue for external contributors
Milestone

Comments

@carlossanlop
Copy link
Member

Closely related to #83072, additional context in that issue.

When constructing a NamedPipeClientStream instance using the constructor that takes a SafePipeHandle, if you set the isConnected argument to false, then call client.Connect(), instead of reusing the pipe handle that was passed in the constructor, the Connect method attempts to create another pipe handle using the same name that was already used by the existing handle, which ends up throwing.

I have a working example here: https://github.com/carlossanlop/experiments/tree/NamedPipeClientStream_ReadMode

SafePipeHandle safePipeHandle = ConstructAPipeHandleWithoutConnectingIt();

NamedPipeClientStream client = new(
            direction,
            isAsync,
            isConnected: false, // Don't connect it yet
            safePipeHandle);

client.Connect(); // this throws

If you test the working example by changing this isConnected argument to false, and then add a client.Connect() invocation right after constructing the stream (somewhere here), the method will throw.

If there is a way to connect an existing pipe handle to the server (I suspect via WaitNamedPipe like in here), then we could detect if the user created the current client stream instance by passing a pipe handle, in which case, we should skip all the creation code in TryConnect and skip directly to attempting to connect it.

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Mar 7, 2023
@ghost
Copy link

ghost commented Mar 7, 2023

Tagging subscribers to this area: @dotnet/area-system-io
See info in area-owners.md if you want to be subscribed.

Issue Details

Closely related to #83072, additional context in that issue.

When constructing a NamedPipeClientStream instance using the constructor that takes a SafePipeHandle, if you set the isConnected argument to false, then call client.Connect(), instead of reusing the pipe handle that was passed in the constructor, the Connect method attempts to create another pipe handle using the same name that was already used by the existing handle, which ends up throwing.

I have a working example here: https://github.com/carlossanlop/experiments/tree/NamedPipeClientStream_ReadMode

SafePipeHandle safePipeHandle = ConstructAPipeHandleWithoutConnectingIt();

NamedPipeClientStream client = new(
            direction,
            isAsync,
            isConnected: false, // Don't connect it yet
            safePipeHandle);

client.Connect(); // this throws

If you test the working example by changing this isConnected argument to false, and then add a client.Connect() invocation right after constructing the stream (somewhere here), the method will throw.

If there is a way to connect an existing pipe handle to the server (I suspect via WaitNamedPipe like in here), then we could detect if the user created the current client stream instance by passing a pipe handle, in which case, we should skip all the creation code in TryConnect and skip directly to attempting to connect it.

Author: carlossanlop
Assignees: -
Labels:

area-System.IO

Milestone: -

@adamsitnik adamsitnik added this to the Future milestone May 19, 2023
@ghost ghost removed the untriaged New issue has not been triaged by the area owner label May 19, 2023
@adamsitnik adamsitnik added the help wanted [up-for-grabs] Good issue for external contributors label May 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-System.IO help wanted [up-for-grabs] Good issue for external contributors
Projects
None yet
Development

No branches or pull requests

2 participants