GithubHelp home page GithubHelp logo

Comments (13)

HavenDV avatar HavenDV commented on August 25, 2024 1

I have released a new version with a suggested fix, please check it out. The ideal situation would be if you could write a test that fails in the version of the library before this fix, so that the situation does not happen again and I do not miss anything.

from h.pipes.

HavenDV avatar HavenDV commented on August 25, 2024

I remember having some problems with Debug when I didn't use H.Pipes.AccessControl for the server. Are you using it? In particular server.AllowUsersReadWrite();

from h.pipes.

erezwanderman avatar erezwanderman commented on August 25, 2024

Yes, I used H.Formatters.MessagePack & H.Pipes.AccessControl in the original program but not in this reproduction example.

Now added them in a new branch: https://github.com/erezwanderman/HPipeMultiClient/tree/MessagePack%26AccessControl.
It does not change behaviour. still crashing.

from h.pipes.

erezwanderman avatar erezwanderman commented on August 25, 2024

After analyzing it furthuer, I think that in IO/PipeStreamWriter.cs, PipeStreamWriter.WriteAsync, the call BaseStream.WriteAsync sends the response, and sometimes the client is fast enough to quickly disconnect before the server finishes flushing and draining, and then the server throws exception on flushing or draining.

It can be avoided by catching and ignoring in
PipeStreamWriter.cs call "await BaseStream.FlushAsync(cancellationToken).ConfigureAwait(false);"
PipeStreamWrapper.cs call "Writer.WaitForPipeDrain()"

I think this Stack Overflow question and answer addresses this exact problem.

Idea for solution: have a closing-handshake. When calling DisconnectAsync or DisposeAsync on PipeClient, do not disconnect but rather send a message to the server to disconnect. And then the server will disconnect.

from h.pipes.

erezwanderman avatar erezwanderman commented on August 25, 2024

Thanks! This fixes the issue and now the program works without exceptions.

from h.pipes.

pontusbredin avatar pontusbredin commented on August 25, 2024

Hi, I'm evaluating some c# Named Pipes nugets and while testing this one I encountered this "Pipe is broken" problem, perhaps in a little bit different way but none the less.

I started the ConsoleApp sample and used a SysInternals tool called accesschk.exe to check what it reports. Upon doing so I can't catch any exceptions, but the pipe server stops working after a single calling like this

accesschk.exe \pipe\named_pipe_test_server

The tool prints a list of permissions set on the pipe and then very quickly disconnects. Perhaps this tool can be used to find out what happens in H.Pipe, and perhaps prevent the pipeserver from stop serving clients. I find it very useful to check that running pipeservers do have the right permissions. Unfortunately meny named pipe implementations fail to handle this tools rather crude behaviour.

This nuget seams to be a very nice package, thank you!

from h.pipes.

Yakonrus avatar Yakonrus commented on August 25, 2024

The problem is computer related.
I have a client server application.
On the server - 4 PipeServers.
I'm running 17 client applications on same laptop, each with 4 PipeClient.
On i7 10870H it works more or less.
On i5 4210U - permanent IOException: 'Pipe is broken'
CPU usage is very high.

from h.pipes.

HavenDV avatar HavenDV commented on August 25, 2024

The problem is computer related. I have a client server application. On the server - 4 PipeServers. I'm running 17 client applications on same laptop, each with 4 PipeClient. On i7 10870H it works more or less. On i5 4210U - permanent IOException: 'Pipe is broken' CPU usage is very high.

Just to be sure - are your clients and servers console applications?

from h.pipes.

Yakonrus avatar Yakonrus commented on August 25, 2024

No, .NET 6, WPF
And this is a highly loaded application. Therefore, perhaps on a weak computer it becomes noticeable.

from h.pipes.

HavenDV avatar HavenDV commented on August 25, 2024

I will write tests for high-load situations when I have free time.
You can speed up this process if you wish. Submitting a PR with a test that will work on both of your computers will greatly speed up the fix for this issue. You can take these tests as a basis, run several copies in parallel, generating names for the pipes:
https://github.com/HavenDV/H.Pipes/blob/master/src/tests/H.Pipes.Tests/DataTests.cs

from h.pipes.

Yakonrus avatar Yakonrus commented on August 25, 2024

The problem is that I have to isolate the Canon EDSDK dll, the only option was to run a separate client for each camera.
I am using modified: https://github.com/acdvorak/named-pipe-wrapper
There are problems here too.
0x800705AA insufficient system resource
I decided to find another solution. I tried your library.

I'll check later.

from h.pipes.

Yakonrus avatar Yakonrus commented on August 25, 2024

Wanted so to follow a lot of connections.
But for some reason even one client does not connect.
What am I doing wrong?

    [TestMethod]
    public async Task TypeTest()
    {
        using var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromMinutes(1));
        var completionSource = new TaskCompletionSource<bool>(false);
        using var registration = cancellationTokenSource.Token.Register(() => completionSource.TrySetCanceled());

        var formatter = new BinaryFormatter();
        
        const string pipeName = "data_test_pipe";

        await using var server = new PipeServer<byte[]>(pipeName, formatter);
        server.ExceptionOccurred += (_, args) => Assert.Fail(args.Exception.ToString());
        server.MessageReceived += (_, args) =>
        {
            Console.WriteLine($"MessageReceived: {args.Message[0]}");
            completionSource.TrySetResult(true);
        };

        await server.StartAsync(cancellationTokenSource.Token);

        Task[] tasks = new Task[1];
        for (int j = 0; j < tasks.Length; j++)
        {
            int i = j;
            tasks[i] = Multi(i, pipeName);
        }
        Task.WaitAll(tasks);

        Assert.IsTrue(await completionSource.Task);
    }

    private async Task Multi(int i, string pipeName)
    {
        using var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromMinutes(1));

        var formatter = new BinaryFormatter();

        await using var client = new PipeClient<byte[]>(pipeName, formatter: formatter);

        client.ExceptionOccurred += (_, args) => Assert.Fail(args.Exception.ToString());

        await client.ConnectAsync(cancellationTokenSource.Token);

        byte[] bytes = new byte[1024 * 1024];
        bytes[0] = (byte)(i+1);

        await client.WriteAsync(bytes, cancellationTokenSource.Token);
    }

from h.pipes.

HavenDV avatar HavenDV commented on August 25, 2024

Replace Task.WaitAll(tasks); to await Task.WhenAll(tasks);.

from h.pipes.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.