HavenDV / H.Pipes

A simple, easy to use, strongly-typed, async wrapper around .NET named pipes.
MIT License
242 stars 26 forks source link

Returned by server pipeName is null #20

Open juergstaub opened 2 years ago

juergstaub commented 2 years ago

Describe the bug

We are sporadically seeing the following exception when connecting > 1 pipeclient with pipeClient.ConnectAsync()

System.InvalidOperationException: Connection failed: Returned by server pipeName is null at H.Pipes.PipeClient1.GetConnectionPipeName(CancellationToken cancellationToken) at H.Pipes.PipeClient1.GetConnectionPipeName(CancellationToken cancellationToken) at H.Pipes.PipeClient1.ConnectAsync(CancellationToken cancellationToken)`

Clients are connected in a relatively short time, the problem is already visible with 3 clients, but does not happen all the time.

Steps to reproduce the bug

Create pipe server Create multiple pipe clients

Expected behavior

All pipe clients connect normally and without ab exception

Screenshots

No response

NuGet package version

Platform

Console

IDE

Other

Additional context

No response

juergstaub commented 2 years ago

I able to mitigate the problem by adding a random delay before ConnectAsync:

var r = new Random();
 await Task.Delay(r.Next(2000, 5000));
await pipeClient.ConnectAsync();
HavenDV commented 2 years ago

Thanks for the problem and detailed description. Yes, indeed, the main pipe of the server accepts requests one at a time, and there may be problems with simultaneous requests from several clients.

Comments for correction (to me in the future or anyone who wants to do this):

I'll get into this after checking out this PR - https://github.com/HavenDV/H.Pipes/pull/19 because it changes the code a lot.