Skip to content

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

@renetenthije

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());
     }
}

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