Skip to content

Exception in the named pipe Serverloop creates huge logfiles and high CPU usage #81

Closed

Description

@renetenthije

The Serverloop in NpListener.cs calls ProcessNextClient() in a while loop. If an exception is thrown in the ProcessNextClient method, a message is logged and the loop continues. From the comment line I understand that this is done on purpose, but the result is that it writes log messages as fast as it can when an exceptions happens repeatedly. In my case that resulted in a logfile over 1 gigabyte within 1 or 2 minutes and a high CPU usage. Exceptions can happen there for more reasons than reaching the connection limit only. In our case it was an UnauthorizedAccessException. Another reason could be an invalid pipename e.g.

I don't know what the best solution would be. Maybe silently catch the specific exception that is triggered by exceeding the number of available connections, pause for 50ms and continue? And re-throw all other exceptions?

private void ServerLoop()
{
    while (running)
    {
        ProcessNextClient();
    }
}

public void ProcessNextClient()
{
    try
    {
        // pipe code
        // every exception thrown here causes a log message 
    }
    catch (Exception e)
    {
        //If there are no more avail connections (254 is in use already) then just keep looping until one is avail
        _log.Error("ProcessNextClient error: {0}", e.ToString().Flatten());
     }
}

Activity

  1. tylerje commented on Jan 11, 2024

    @tylerje
    Member

    Or only log the Nth instance of the exception? I'll try to get to this soon.

  2. RoVaDePi commented on Jan 24, 2025

    @RoVaDePi

    Also ran into this issue, when launching the host multiple times the named pipe already exists and causes UnauthorizedAccessException. Current workaround seems to be to manually attempt connection at launch, and only if that fails setup the servicewire host.

  3. tylerje commented on Aug 18, 2026

    @tylerje
    Member

    Resolved for 6.0.1. The named-pipe listener now retries only the transient Windows pipe-capacity condition (ERROR_PIPE_BUSY) with a short backoff. Other failures, including UnauthorizedAccessException, escape to ServerLoop, fault the host, emit one fatal entry, and stop the listener instead of entering an unbounded CPU/logging loop. Added targeted regression coverage on .NET 10 and .NET Framework 4.8.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      ⌂ 换网址